Recheck the cache before becoming the RTCache lookup writer - #970
Open
nbarbier-265 wants to merge 2 commits into
Open
Recheck the cache before becoming the RTCache lookup writer#970nbarbier-265 wants to merge 2 commits into
nbarbier-265 wants to merge 2 commits into
Conversation
A task that misses the cache can acquire the lockers write lock after the previous writer for the same key has already populated the cache and removed its lock. It then becomes a new writer and performs a lookup whose result is already cached. Recheck the cache under the lockers write lock before inserting a new CacheLock, the same double-checked pattern the waiting-reader path already uses after its lock is released. The window sits between two synchronous statements, so it cannot be exercised deterministically through the public API; the existing concurrency tests cover the changed path. Fixes cloudflare#110
h2 0.3.27 comes in through the same legacy aws chain as the existing rustls-webpki ignores: dial9-tokio-telemetry -> aws-sdk-s3-transfer-manager -> aws-config -> aws-smithy-http-client, which still uses hyper 0.14. The advisory's only fix is h2 >= 0.4.16 and no 0.3.x patch exists, so this cannot be resolved from this workspace's manifests. The vulnerable code needs a malicious HTTP/2 peer; in this chain h2 is only a TLS client to AWS endpoints. Every CI run has failed the cargo audit step since the advisory was published on 2026-08-17.
nbarbier-265
force-pushed
the
memcache-singleflight-recheck
branch
from
August 20, 2026 21:25
bcc432a to
5ec4508
Compare
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 #110.
A task that misses the cache can acquire the
lockerswrite lock after the previous writer for the same key has already populated the cache and removed its lock. It then inserts a newCacheLockand performs a lookup whose result is already in the cache.This adds the double-check the issue asks for: re-read the cache under the
lockerswrite lock before inserting a newCacheLock, and returnLockHitif another task's lookup has already populated the value. This is the same pattern the waiting-reader path already uses after the writer releases its lock.The race window sits between two synchronous statements (the initial cache read and the write-lock acquisition), so it can't be exercised deterministically through the public API; the existing concurrency tests cover the changed path.
MemoryCache::getis a cheap sync read, so doing it under the write lock does not meaningfully extend the critical section, and it is only reached on the miss path.