Skip to content

fix(edge-config): stale-if-error expiry check was inverted - #1091

Open
Diwak4r wants to merge 2 commits into
vercel:mainfrom
Diwak4r:fix/stale-if-error-expiry-check
Open

fix(edge-config): stale-if-error expiry check was inverted#1091
Diwak4r wants to merge 2 commits into
vercel:mainfrom
Diwak4r:fix/stale-if-error-expiry-check

Conversation

@Diwak4r

@Diwak4r Diwak4r commented Jul 27, 2026

Copy link
Copy Markdown

Summary

The stale-if-error cache expiry check in fetch-with-cached-response.ts was 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:

cachedResponseEntry.time < Date.now() + staleIfError * 1000

This evaluates to true for any positive staleIfError because Date.now() + staleIfError * 1000 is 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 handleStaleIfError and handleStaleIfErrorException) to:

Date.now() < cachedResponseEntry.time + staleIfError * 1000

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.

Copilot AI review requested due to automatic review settings July 27, 2026 09:56
@changeset-bot

changeset-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: adff314

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@vercel/edge-config Patch
@vercel/global-config Patch
vercel-storage-integration-test-suite Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Jul 27, 2026

Copy link
Copy Markdown
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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Diwak4r
Diwak4r force-pushed the fix/stale-if-error-expiry-check branch from c4c1b3e to d3aefff Compare August 4, 2026 06:41
…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>
@Diwak4r
Diwak4r force-pushed the fix/stale-if-error-expiry-check branch from d3aefff to d2eb1d5 Compare August 7, 2026 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants