fix(edge-config): stale-if-error expiry check was inverted - #1091
Open
Diwak4r wants to merge 1 commit into
Open
Conversation
…tale forever The expiry condition compared cache time to (now + staleIfError * 1000), which always evaluates to true for any positive staleIfError duration. This means stale-if-error caches never expired, indefinitely serving stale content despite being well past the configured window. Fix: change condition to check Date.now() < cacheEntry.time + staleIfError * 1000, only serving stale content when the expiry window has not yet elapsed. Also applies the same correction to the network-error path (createHandleStaleIfErrorException). Added regression test: stale content should NOT be served after the window expires (advancing 11s past a 10s stale-if-error=10 window should throw). Signed-off-by: Diwak4r <rv2njztef7@gmail.com>
|
Contributor
|
@Normanyadav is attempting to deploy a commit to the Curated Tests - Permanent E2E Team on Vercel. A member of the Team first needs to authorize it. |
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
The stale-if-error cache expiry check in
fetch-with-cached-response.tswas inverted, causing stale-if-error caches to **never expire** — they would indefinitely serve stale content regardless of how much time passed.Bug
The condition compared:
This evaluates to
truefor any positivestaleIfErrorbecauseDate.now() + staleIfError * 1000is always in the future. The cache entry time is always less than a future timestamp, so stale content is served forever.Fix
Changed the comparison (in both
handleStaleIfErrorandhandleStaleIfErrorException) to:This correctly checks whether
Date.now()has exceeded the cache entry time plus the stale-if-error window — only serving stale content when the window has not yet elapsed.Test
Added a regression test: after advancing time past the stale-if-error window (11s past a 10s
stale-if-error=10), a network-fault fetch should throw — not serve stale content. The test fails before the fix and passes after.