Repository navigation
Conversation
(except for LRUCache), and this caused a segfault in free-threaded versions. From now on, in all free-threaded versions, this will raise a RuntimeError in all cache implementations.
awolverp
pushed a commit
that referenced
this pull request
Oct 28, 2026
Views (keys/values/items, LFU items_with_frequency, TTL items_with_expire) hold raw positions into the policy storage and rely on the generation version to notice changes. They compared the generation without holding the cache lock and then read, so on free-threaded builds another thread could free or move entries in between (#94 reported this crash; #98 made replace() bump the generation, but the check-then-read race remained). - implement_view_guard! now generates lock_and_check(): take the cache lock, then compare the generation, and return the guard so it is held while reading. The unlocked check_generation() is removed, so every view method goes through the lock (__next__, __len__, and TTL/VTTL __bool__). - View fields hold the typed cache (Py<PyXCache>) to reach its lock. - TTL view constructors created the iterator and read the generation under two separate locks; a mutation in between made stale positions look current. Both now happen under one lock, as VTTL already did. - docs: iterator methods take the cache lock; calling them from code that runs inside an operation on the same cache (a key's __eq__, a value's __del__) blocks, like cache[key] there. Refs #94
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #94.
Replacing the value of an existing key while iterating was not a problem (except for
LRUCache), and this caused a segfault in free-threading versions. From now on, in all free-threading versions, this will raise aRuntimeErrorin all cache implementations.