This repository was archived by the owner on Oct 25, 2026. It is now read-only.
Repository navigation
Conversation
Since listpack hashes can carry field TTLs, a field that has expired but not yet been reaped by active expire stays in the listpack. HGETALL, HSCAN and the hashtable branch of ScanKey all hide it, but the listpack branches of ValkeyModule_ScanKey and ValkeyModule_ScanKeyRawBorrowed delivered it to the module callback. Apply the same visibility check HSCAN uses to both listpack loops. Signed-off-by: Madelyn Olson <madelyneolson@gmail.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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Since valkey-io/valkey#3212, a listpack hash can hold a field that has expired but has not yet been reaped by active expire.
HGETALL,HSCAN, and the hashtable branch ofValkeyModule_ScanKeyall hide that field, but the listpack branches ofValkeyModule_ScanKeyandValkeyModule_ScanKeyRawBorrowedpass it to the module callback. A module that indexes hashes through ScanKey, such as valkey-search, sees data the client can no longer read. The fix applies the visibility checkHSCANalready uses to both listpack loops.AI generated details
Based on valkey-io/valkey
unstableat8f67ab136, so the base branch here isupstream-unstable-8f67ab136.Problem
valkey-io/valkey#3212 (c80da01) stores a field's TTL as a metadata entry after its value in the listpack. Readers have to check it explicitly with
hashTypeListpackFieldIsValid().hashTypeNext()(t_hash.c:900) andHSCAN(db.c:1391) do. The hashtable branch of ScanKey gets the same filtering fromhashtableScan'svalidateEntrycallback.The listpack loops in
VM_ScanKey(module.c:12320) andVM_ScanKeyRawBorrowed(module.c:12469, added in valkey-io/valkey#4403) walk field/value pairs withlpNext().lpNext()skips over metadata entries, so neither loop ever reads the expiry.Both commits are in 9.2.0-rc1 only.
The existing
scan.tcltests never set a field TTL, so nothing exercised this.8f67ab136Fix
Once each loop reaches the value entry, it checks
hashTypeListpackFieldIsValid(hashTypeListpackGetExpiry(lp, vptr))and skips the pair if the field is not visible. This is the same checkHSCANuses, so expiration policy (POLICY_IGNORE_EXPIREduring loading, on replicas, and so on) behaves the same way on both encodings. Zset listpacks carry no metadata, sohashTypeListpackGetExpiry()returnsEXPIRY_NONEfor them and they are never skipped.Alternative considered
Rewrite the hash case on top of
hashTypeInitIterator()/hashTypeNext(), which already filter. That would split the loop, which is shared with listpack zsets, and the RawBorrowed variant would still have to unpack integer-encoded entries on its own. Two added checks are a smaller cherry-pick into 9.2.Testing
The new tests in
tests/unit/moduleapi/scan.tclturn off active expire, let one field of a two-field listpack hash expire, and confirm it was not reaped (HLENis still 2, encoding is still listpack). With themodule.chunks reverted:Removing either guard on its own fails only the test for that function.
This was generated by AI but verified, with love, by a human.