Repository navigation
Conversation
… eviction of refreshed items When an item is refreshed (added again) to a LimitedSet, the old heap entry remains in _heap while _data[item] is replaced with the newer entry. The stale entry could cause the current entry to be removed prematurely during purge(). Fix by having purge()'s expiry branch use identity comparison (current is entry) to distinguish stale heap entries from current ones, and by having pop() skip stale entries via the same check. Includes regression test test_refresh_does_not_evict_item_until_new_expiry. Closes celery#10506
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 #10506
When an item is refreshed (added again) to a
LimitedSet, the old heap entry remains in_heapwhile_data[item]is replaced with the newer entry. The stale entry could cause the current entry to be removed prematurely duringpurge().Root cause
purge()'s expiry branch calledself.pop(), which blindly removes the oldest item from_data— even when the heap entry it popped was stale (the item had been refreshed since that entry was pushed).Fix
purge()expiry branch: directly inspectself._heap[0]with identity comparison to distinguish stale heap entries from current ones. Only delete from_datawhen the entry is both expired and current.pop(): use the same identity check to skip stale heap entries instead of blindly removing the item from_data.Testing
Added
test_refresh_does_not_evict_item_until_new_expiry— a regression test that reproduces the exact scenario from the issue.All 52 tests in
test_collections.pypass.