Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix LruCache corruption bug with a size_callback that can return 0 #11454

Merged
merged 8 commits into from
Nov 30, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion synapse/util/caches/lrucache.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,10 @@ def drop_from_cache(self) -> None:
removed from all lists.
"""
cache = self._cache()
if cache is None or cache.pop(self.key, None) is None:
if (
cache is None
or cache.pop(self.key, _Sentinel.sentinel) is _Sentinel.sentinel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that we can store None as a value in the cache?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the thinking, yes.

Although drop_from_lists is idempotent so it's functionally the same

):
# `cache.pop` should call `drop_from_lists()`, unless this Node had
# already been removed from the cache.
self.drop_from_lists()
Expand Down