Skip to content

Fix LimitedSet.purge race with an instance lock - #11149

Open
FullStraing wants to merge 4 commits into
celery:mainfrom
FullStraing:fix/limitedset-purge-race-11141
Open

FullStraing wants to merge 4 commits into
celery:mainfrom
FullStraing:fix/limitedset-purge-race-11141

Conversation

@FullStraing

@FullStraing FullStraing commented Nov 22, 2026 •

Copy link
Copy Markdown

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.

@auvipy
auvipy self-requested a review November 23, 2026 02:54
@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.33%. Comparing base (29b14de) to head (7d7f2be).

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     
Flag Coverage Δ
unittests 91.31% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@auvipy auvipy added this to the 5.7.x milestone Nov 23, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Race: LimitedSet.purge reads heap[0] while a concurrent pop empties it (IndexError)

2 participants