tkem / cachetools

Extensible memoizing collections and decorators
MIT License
2.28k stars 163 forks source link

Race condition in cachetools causing cache to stuck in error #288

Closed Dor-Shwartz closed 11 months ago

Dor-Shwartz commented 11 months ago

We are using cachetools to wrap access to our db. From a certain point, we started receiving the following error consistently.

File "/usr/local/lib/python3.10/site-packages/cachetools/init.py", line 739, in wrapper cache[k] = v File "/usr/local/lib/python3.10/site-packages/cachetools/init.py", line 422, in setitem self.expire(time) File "/usr/local/lib/python3.10/site-packages/cachetools/init.py", line 476, in expire cache_delitem(self, curr.key) File "/usr/local/lib/python3.10/site-packages/cachetools/init.py", line 90, in delitem del self.__data[key] KeyError: ()

tkem commented 11 months ago

You are probably using a shared cache in a threaded environment without proper locking. See also