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

Next/Image: Cancelled Image Request Hangs That Image Until Server Restart

A cancelled request to /_next/image leaves a stale in-flight promise in the image optimization cache, causing subsequent requests for the same image URL to hang indefinitely until server restart.

highConfidence 73%Next.jsAffected V15.5.xAffected V15.5.25Fixed V16.4.0-Canary.48

Origin Analysis

The image optimization endpoint uses a per-URL cache to deduplicate concurrent image processing. When a client cancels the request before completion, the abort signal is not properly handled: the cached promise is neither rejected nor removed, so later requests for the same URL await an unresolved promise, causing a permanent hang for that image.
1. Install next@15.5.25. 2. Build and start the app with a local image served via next/image. 3. Request the image through /_next/image and immediately cancel the request (e.g., close browser tab or abort fetch). 4. Request the same image URL again. 5. Observe that the second request hangs indefinitely; only a server restart clears the stuck state.

Fixing Code Block

Edge Case Audit

This patch assumes the optimizeImage function supports an AbortSignal; if it ignores the signal, the underlying I/O may not be cancelled and the promise could still hang. Validate on Node 18/20/24 and Windows. Backport to 15.5.x may require adapting to the existing AbortSignal API; test concurrent cancellations and multiple image URLs. Rollback: remove the patch and restart the server; the original bug will return.

Ecosystem Topology