Fix race in ThreadSafeSingleton

This commit is contained in:
rda-dev 2020-11-10 18:53:52 +03:00
parent 4120afd1c3
commit f28abb2869
No known key found for this signature in database
GPG Key ID: 8900C7C5C15B294F

View File

@ -2178,15 +2178,19 @@ cdef class ThreadSafeSingleton(BaseSingleton):
:rtype: None
"""
with self.__storage_lock:
self.__storage = None
cpdef object _provide(self, tuple args, dict kwargs):
"""Return single instance."""
storage = self.__storage
if storage is None:
with self.__storage_lock:
if self.__storage is None:
self.__storage = __factory_call(self.__instantiator,
args, kwargs)
return self.__storage
storage = self.__storage
return storage
cdef class DelegatedThreadSafeSingleton(ThreadSafeSingleton):