-
Notifications
You must be signed in to change notification settings - Fork 61
Description
It appears that the alru_cache
decorator is using an unsynchronized OrderedDict
instance for its cache:
async-lru/async_lru/__init__.py
Line 103 in dc601e2
self.__cache: OrderedDict[Hashable, _CacheItem[_R]] = OrderedDict() |
If I am not mistaken, that will lead to a data race if the decorated function is called simultaneously from different asyncio
event loops running on different threads β which seems to be a realistic (if rare) situation (compare python/cpython#93462 (comment)).
If I understand correctly, other asyncio
wrappers generally bind the event loop during initialization and fail explicitly if called from a different event loop. Unfortunately, since the alru_cache
decorator generally runs at module init time there is no such loop on the thread.
I don't have a clear idea of how this problem could be fixed; I just wanted to point it out as a (significant and subtle) risk for users of this module.