diff --git a/lib/internal/streams/destroy.js b/lib/internal/streams/destroy.js index efa09e05eafef0..e68630ec3ef833 100644 --- a/lib/internal/streams/destroy.js +++ b/lib/internal/streams/destroy.js @@ -326,12 +326,12 @@ function emitErrorCloseLegacy(stream, err) { } // Normalize destroy for legacy. -function destroyer(stream, err) { +function destroyer(stream, err, options) { if (!stream || isDestroyed(stream)) { return; } - if (!err && !isFinished(stream)) { + if (!err && !isFinished(stream) && options?.autoAbort !== false) { err = new AbortError(); } diff --git a/lib/internal/streams/readable.js b/lib/internal/streams/readable.js index 37469311067c28..54bcf9a9b5f39f 100644 --- a/lib/internal/streams/readable.js +++ b/lib/internal/streams/readable.js @@ -1150,7 +1150,9 @@ async function* createAsyncIterator(stream, options) { (error || options?.destroyOnReturn !== false) && (error === undefined || stream._readableState.autoDestroy) ) { - destroyImpl.destroyer(stream, null); + destroyImpl.destroyer(stream, null, { + autoAbort: false + }); } } }