Fix ThreadSafeSingleton synchronization issue (#434)

* Fix ThreadSafeSingleton synchronization issue

* Update changelog
This commit is contained in:
Roman Mogylatov 2021-03-23 21:14:03 -04:00 committed by GitHub
parent fca9fd498c
commit 1aef599606
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 2951 additions and 2969 deletions

View File

@ -7,6 +7,12 @@ that were made in every particular version.
From version 0.7.6 *Dependency Injector* framework strictly From version 0.7.6 *Dependency Injector* framework strictly
follows `Semantic versioning`_ follows `Semantic versioning`_
Development version
-------------------
- Fix ``ThreadSafeSingleton`` synchronization issue.
See issue: `#433 <https://github.com/ets-labs/python-dependency-injector/issues/433>`_.
Thanks to `@garlandhu <https://github.com/garlandhu>`_ for reporting the issue.
4.31.0 4.31.0
------ ------
- Implement providers' lazy initialization. - Implement providers' lazy initialization.

File diff suppressed because it is too large Load Diff

View File

@ -2819,17 +2819,14 @@ cdef class ThreadSafeSingleton(BaseSingleton):
if instance is None: if instance is None:
with self.__storage_lock: with self.__storage_lock:
if self.__storage is None: if self.__storage is None:
instance = __factory_call(self.__instantiator, args, kwargs) result = __factory_call(self.__instantiator, args, kwargs)
if __is_future_or_coroutine(result):
if __is_future_or_coroutine(instance):
future_result = asyncio.Future() future_result = asyncio.Future()
instance = asyncio.ensure_future(instance) result = asyncio.ensure_future(result)
instance.add_done_callback(functools.partial(self._async_init_instance, future_result)) result.add_done_callback(functools.partial(self._async_init_instance, future_result))
self.__storage = future_result result = future_result
return future_result self.__storage = result
instance = self.__storage
self.__storage = instance
return instance return instance