mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-03 15:54:49 -04:00
Fix LruCache
corruption bug with a size_callback
that can return 0 (#11454)
When all entries in an `LruCache` have a size of 0 according to the provided `size_callback`, and `drop_from_cache` is called on a cache node, the node would be unlinked from the LRU linked list but remain in the cache dictionary. An assertion would be later be tripped due to the inconsistency. Avoid unintentionally calling `__len__` and use a strict `is None` check instead when unwrapping the weak reference.
This commit is contained in:
parent
5a0b652d36
commit
7ff22d6da4
3 changed files with 17 additions and 1 deletions
|
@ -271,7 +271,10 @@ class _Node(Generic[KT, VT]):
|
|||
removed from all lists.
|
||||
"""
|
||||
cache = self._cache()
|
||||
if not cache or not cache.pop(self.key, None):
|
||||
if (
|
||||
cache is None
|
||||
or cache.pop(self.key, _Sentinel.sentinel) is _Sentinel.sentinel
|
||||
):
|
||||
# `cache.pop` should call `drop_from_lists()`, unless this Node had
|
||||
# already been removed from the cache.
|
||||
self.drop_from_lists()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue