fix: release per-key coalescing lock when RTCache writer is cancelled - #948
Open
stareezy-1 wants to merge 2 commits into
Open
fix: release per-key coalescing lock when RTCache writer is cancelled#948stareezy-1 wants to merge 2 commits into
stareezy-1 wants to merge 2 commits into
Conversation
A cache-miss writer inserts a zero-permit CacheLock before awaiting the user Lookup callback, and only removed it after the lookup completed. If the get() future was cancelled while the callback was pending, the lock remained installed with zero permits and no live owner, blocking all later same-key requests indefinitely (or bypassing normal coalescing with lock_timeout/lock_age). Introduce a WriterLockGuard that owns the inserted lock entry: on drop, including cancellation of the writer future, it wakes waiters and removes the lock from the lockers map, guarded by an Arc identity check so a cancelled old writer never deletes a newer writer's lock.
Refactoring the writer cleanup into the guard's Drop left a bare 'let ret = ...; ret' tail, which clippy::let_and_return rejects under -D warnings on Rust 1.91.
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.
Summary
Fixes #931
Problem
RTCache::get()inserts a zero-permitCacheLockintolockerson a cache miss, then awaits the user-providedLookup::lookup()callback. The lock was only released and removed after the lookup completed:If the
get()future is cancelled while the callback is pending (timeout, losingselect!branch, task abort, runtime shutdown), the lock stays installed with zero permits and no live owner. Later same-key requests then:lock_age = None/lock_timeout = None(per-key liveness failure), orlock_timeout/lock_ageset.Fix
Introduce a
WriterLockGuardthat owns the inserted lock entry:add_permits) and removes the lock fromlockers.Arcidentity check so a cancelled old writer never deletes a newer writer's lock.lockersbecomesArc<RwLock<...>>so the guard can reach it without borrowing the cache.Tests
test_cancelled_lookup_releases_coalescing_lock(inverted from the issue's whitebox repro):lookup()then is abortedlockersno longer contains the keyget()completes with a fresh lookupFull crate suite passes (
cargo test -p pingora-memory-cache),cargo fmt --checkand clippy clean.