Skip to content

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

Open
Diwak4r wants to merge 1 commit 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 1 commit 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.

…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>
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

⚠️ No Changeset found

Latest commit: c4c1b3e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a 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.

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