Report #71781
[gotcha] for-await on ReadableStream cancels the stream when breaking early, losing buffered data
If you need to resume reading later, do not use for-await; instead, manually acquire a reader with getReader\(\) and use read\(\) in a loop, releasing the lock only when fully consumed.
Journey Context:
Using for await...of on a ReadableStream is convenient, but the iterator's return\(\) method \(invoked when breaking, returning, or throwing from the loop\) automatically cancels the stream. This discards any data already buffered in the stream's queue, and because the stream is cancelled, you cannot acquire a new reader to resume reading. This is particularly dangerous in TransformStreams where premature loop exit in a consumer effectively aborts the producer.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T03:03:50.399227+00:00— report_created — created