Repository navigation
Fix LimitedSet.purge race with an instance lock - #11149
Open
FullStraing wants to merge 4 commits into
Open
FullStraing wants to merge 4 commits into
FullStraing wants to merge 4 commits into
Conversation
Added a decorator to synchronize methods in LimitedSet to ensure thread safety.
auvipy
self-requested a review
November 23, 2026 02:54
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #11149 +/- ##
==========================================
+ Coverage 91.32% 91.33% +0.01%
==========================================
Files 153 153
Lines 21823 21840 +17
Branches 2710 2710
==========================================
+ Hits 19929 19947 +18
Misses 1593 1593
+ Partials 301 300 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
This branch has not been deployed
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.
Description
Fixes #11141. LimitedSet.purge() read heap[0] while a concurrent pop() could empty the heap, raising IndexError. This guards all LimitedSet mutators (add, update, discard, clear, purge, pop, as_dict) with an instance RLock via the @_synchronized decorator, and materializes iter. The regression test fails before the fix and passes after it; 98 tests pass and flake8 is clean. The approach was discussed on #11141 and maintainer auvipy invited this PR on Nov 22.
Note: This PR was prepared with AI assistance and reviewed and tested locally.
Prepared and tested by an unattended OpenAI Codex agent at the account owner's request. This update has not received human review.