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

Segment Prefetch Of An ISR NotFound() Page Never Completes In Chromium When A Service Worker Mediates Fetches (Wedges Connections, Networkidle Never Reached)

Next.js segment cache abandons response bodies for rejected prefetch responses; with a service worker, unconsumed respondWith bodies cause Chromium to keep fetches pending forever, exhausting connections and breaking networkidle.

highConfidence 92%Next.jsAffected V16.2.12Affected V16.3.1-Canary.4

Origin Analysis

When a segment prefetch response is rejected (e.g. 404 from ISR notFound), the client code does not read or cancel the response body. With a service worker using respondWith, the unconsumed body keeps the request in flight indefinitely.
1. npm install && npx playwright install chromium 2. npm run build (fresh production build) and npm start 3. node probe.mjs — exits 1 when reproduced (deterministically on fresh build) Or by hand: open Chrome DevTools → Network on http://localhost:3000/, reload once (so the service worker controls the page), and watch the segment prefetches of the dead link stay pending forever.

Fixing Code Block

Edge Case Audit

Cancelling a body that is already being consumed elsewhere may throw; the try/catch prevents crashes. Ensure cancellation only after confirming response is not needed. This fix is safe for both service worker and non-SW environments but should be tested with streaming/prefetch scenarios. Rollback by removing cancellation lines; no migration needed.

Ecosystem Topology