{{ message }}
Repository navigation
Conversation
…ry timers Under concurrent Set operations, entries could be retained in Cache.data indefinitely without active timers in TimingWheel due to races between timer expiration callbacks, SetWithExpire, and MoveTimer/RemoveTimer. 1. Track entry generation ID and deadline in cacheEntry. 2. Synchronize SetTimer and RemoveTimer invocations under Cache.lock to preserve registration order. 3. In the timing wheel expiration callback, only delete entries matching the expired generation ID without invoking RemoveTimer. 4. Validate expiration deadline during doGet to prevent serving stale data.
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.

Fixes #5803
Description
Under concurrent
Set/SetWithExpirecalls,collection.Cachecould retain entries inCache.dataindefinitely without active expiry timers inTimingWheel. Consequently,Getcontinued returning hits beyond the configured TTL.Root causes:
TimingWheelinvokedcache.Del(key).Delinvokedc.timingWheel.RemoveTimer(key)outsidec.lock. If a concurrentSetWithExpireregistered a new timer for the same key in between, that new timer was cancelled by the lingeringRemoveTimercall, leaving the new entry inc.datawithout any timer.SetWithExpire,MoveTimerwas invoked when the key was present inc.data. However, if the old timer had already expired or been dequeued fromtw.timers,moveTasksilently did nothing without registering a new timer.Setbefore deleting.Get/doGetdid not validate an expiration deadline, allowing expired entries to be served if timer execution lagged under load.Solution
cacheEntrytracking a monotonic generationidand an expirationdeadline.SetTimerandRemoveTimerunderCache.lockto preserve registration and invalidation ordering.SetWithExpire, always callSetTimerwith the entry generationidso that timers are always properly scheduled or moved.cache.Delin theTimingWheelcallback withdelIfMatch(key, id), ensuring only the entry matching the expired generation ID is removed, and avoid callingRemoveTimerfor an already-expired timer.doGet, validateentry.deadlineand clean up if expired, guaranteeing callers never receive stale data.Tests
TestCacheExpiryConcurrentWritesincore/collection/cache_test.goreproducing the concurrent writer workload from Bug: collection.Cache can retain entries without expiry timers after concurrent Set calls #5803, asserting zero orphans and zero expired survivors.TestCacheExpiryGetincore/collection/cache_test.goverifying deadline validation onGet.go test -v -race ./core/collection/... -count=3andgo test ./core/stores/cache/... ./zrpc/....