Response.clone() in Node's fetch can keep a whole 64 MB download in memory
The Octri monitoring team tested Response.clone()[1] in Node's native fetch while looking for a way to preview the first 4 KB of a response without interfering with it. In a test on Node.js v22.16.0 with a 64 MB file, the clone still held about 64 MB of additional array buffer memory after the download finished, even though only 4,096 bytes were read from it.
The cause is that Response.clone() splits the body into two streams using ReadableStream.tee()[2]. Chunks that the copy has not yet read stay queued, and the queue has no fixed limit. Reading the preview from the clone before the download and cancelling it without awaiting the cancellation brought array buffer memory down to about 0.26 MB in both tests.
The author then considers collecting the preview with a TransformStream[3] while the application reads the original response, which avoids creating a second stream. The article ends before showing that code.
Read the original octri.devDiscussion
Sources
-
Octri
How a tiny HTTP response preview ended up buffering a 64 MB download







