Always untrack initialized safe iterator#3223
Merged
ranshid merged 1 commit intovalkey-io:unstablefrom Feb 17, 2026
Merged
Conversation
Signed-off-by: Ran Shidlansik <ranshid@amazon.com>
madolson
approved these changes
Feb 17, 2026
sarthakaggarwal97
approved these changes
Feb 17, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## unstable #3223 +/- ##
================================
================================
🚀 New features to boost your workflow:
|
Contributor
|
@ranshid does this need to be backported as well to Valkey 9.0? |
Member
Author
@sarthakaggarwal97 no. AFAIK we never backported #2807 which is the source of this specific degradation |
harrylin98
pushed a commit
to harrylin98/valkey_forked
that referenced
this pull request
Feb 19, 2026
in valkey-io#2807 we added safe-iterator invalidation when a hashtable is deleted. When we create a safeIterator we initialize it to it->table=0 and it-index=-1. HOWEVER say someone creates a safe iterator never progress it and later on just delete the iterator using `hashtableReleaseIterator`. the iterator will NOT be untracked since, `hashtableCleanupIterator` will skip the untrack: ```c if (!(iter->index == -1 && iter->table == 0)) { if (isSafe(iter)) { hashtableResumeRehashing(iter->hashtable); untrackSafeIterator(iter); } else { assert(iter->fingerprint == hashtableFingerprint(iter->hashtable)); } } ``` and then when the hashtable is freed the iterator will be referenced leading to a use-after-free. For example: ```c it = hashtableCreateIterator(ht, HASHTABLE_ITER_SAFE); hashtableReleaseIterator(it); hashtableRelease(ht); ``` This PR fix it by ALWAYS untrack safe iterators which have a valid hashtable when they are being cleaned up. Signed-off-by: Ran Shidlansik <ranshid@amazon.com>
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.
in #2807 we added safe-iterator invalidation when a hashtable is deleted.
When we create a safeIterator we initialize it to it->table=0 and it-index=-1.
HOWEVER say someone creates a safe iterator never progress it and later on just delete the iterator using
hashtableReleaseIterator.the iterator will NOT be untracked since,
hashtableCleanupIteratorwill skip the untrack:and then when the hashtable is freed the iterator will be referenced leading to a use-after-free.
For example:
This PR fix it by ALWAYS untrack safe iterators which have a valid hashtable when they are being cleaned up.