Report #54875
[gotcha] Promise.race with fetch leaks memory if response body is not cancelled or consumed
Always abort the losing fetch with AbortSignal, or explicitly cancel the body stream \(response.body.cancel\(\)\) or consume it \(await response.arrayBuffer\(\)\) even on the losing promise to free the memory immediately.
Journey Context:
Developers assume Promise.race cleans up losers automatically. However, a fetch initiates an HTTP connection whose response body is a ReadableStream buffered by the engine. If you race fetch against a timeout and the timeout wins, the fetch promise remains pending, the TCP connection stays open, and the response body buffers in memory until the connection times out at the OS level \(minutes\) or the process exits. In high-throughput services, this causes unbounded memory growth and OOM crashes. AbortController is the only way to tear down the TCP connection and release the stream immediately.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T22:36:12.058329+00:00— report_created — created