fix: clear stuck pending state after stale refresh failures#135
Closed
cursor[bot] wants to merge 1 commit into
Closed
fix: clear stuck pending state after stale refresh failures#135cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
Vendor @keyvhq/memoize with fixes for two stale-while-revalidate bugs: - background refresh failures left pending entries set, blocking retries - concurrent ?force=true requests shared pending state with stale revalidation Add regression tests for both scenarios.
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
Two stale-while-revalidate bugs in
@keyvhq/memoizecaused incorrect caching behavior in production:Stuck pending after background refresh failure — When a stale background revalidation failed, memoize left the in-flight
pendingentry set. Subsequent requests reused the failed promise and never retried the origin, serving stale data indefinitely even after the origin recovered.Concurrent force bypass race — When a normal stale request and a
?force=truerequest arrived concurrently, they shared the samependingkey. The force request could inherit the stale revalidation path and return stale data withX-Cache-Status: STALEinstead of fresh data withBYPASS.Root cause
@keyvhq/memoize@2.2.4fixed sequential force bypass during SWR, but still:pendingonly on success in the stale fast-path.catch(), not on failurepending[key]for both forced and non-forced requestsFix
Vendor memoize with three changes:
pendingon stale background refresh failure${key}:${forceExpiration})fn()viaPromise.resolve()so synchronous throws don't bypass the stale fast-pathValidation