fix: isolate force bypass from concurrent stale revalidation#133
Closed
cursor[bot] wants to merge 1 commit into
Closed
fix: isolate force bypass from concurrent stale revalidation#133cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
When ?force=true raced a normal request during stale-while-revalidate, @keyvhq/memoize deduplicated in-flight work by cache key only, so the force request could inherit the stale fast-path and return old data while reporting STALE instead of BYPASS. Vendor memoize@2.2.4 with separate pending keys for forced bypass and add a concurrent regression test. Co-authored-by: kikohumanbeatbox <kikohumanbeatbox@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 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.
Bug and impact
When
?force=truewas sent concurrently with a normal request during the stale-while-revalidate window, the force request could return stale cached data withX-Cache-Status: STALEinstead of fresh data withBYPASS. This defeats explicit cache invalidation under load — the exact scenario where operators use?force=trueto guarantee a fresh origin fetch.Root cause
@keyvhq/memoizededuplicates in-flight requests using only the cache storage key (URL path). During SWR, a normal request holdspending[key]while serving stale data and revalidating in the background. A concurrent force-bypass request joined that same pending promise and inherited the stale fast-path, even thoughforceExpirationwastrue.The recent
@keyvhq/memoize@2.2.4bump fixed the sequential case (force after stale) but not this concurrent race.Fix
memoize@2.2.4with separate pending keys for forced vs normal requests (${key}:${forceExpiration === true})Validation
BYPASS for forcing refresh when response is stale concurrently