AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Background Cache Regeneration During Streaming Is Not Kept Alive By WaitUntil And Gets Aborted On Vercel

In Next.js 16.3.6 on Vercel, background cache regeneration started during streaming is not tracked by waitUntil, causing it to be aborted when the serverless function exits, resulting in failed revalidations.

highConfidence 85%Next.jsAffected V16.3.6

Origin Analysis

The stale path in use-cache-wrapper was changed to push a detached promise to workStore.pendingRevalidateWrites instead of awaiting it. During streaming, app-render calls executeRevalidates immediately after renderToStream returns, copying the current pendingRevalidateWrites into a waitUntil promise. Any regeneration or cache write promises pushed later (from use cache reads inside Suspense boundaries that resolve during streaming) are never registered with waitUntil, so the serverless function may terminate before they complete.
1. Deploy to Vercel (Node.js runtime, Fluid compute) with cacheComponents: true. 2. Create app/p/[id]/page.js with a Suspense boundary; inside, await params then await a "use cache: remote" function that makes multiple fetch calls and logs steps. 3. Request /p/1 to fill the cache. 4. Wait past the stale time (e.g., 60s) and request /p/10; this starts a background regeneration. 5. Observe function logs: the regeneration only progresses while later requests are running and eventually fails with fetch failed or AbortError.

Fixing Code Block

Edge Case Audit

This workaround may keep the function alive longer than expected, but catching errors prevents unhandled rejections. It should be tested with concurrent requests and on platforms with different execution models. A cleaner fix would be to modify executeRevalidates to keep draining pendingRevalidateWrites until the stream has fully completed. Rollback: revert the patch and downgrade to 16.2.9 if issues arise.

Ecosystem Topology