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 + }); } } } diff --git a/test/parallel/test-stream-pipeline.js b/test/parallel/test-stream-pipeline.js index e650278e911881..061ef923d03a59 100644 --- a/test/parallel/test-stream-pipeline.js +++ b/test/parallel/test-stream-pipeline.js @@ -764,21 +764,21 @@ const tsp = require('timers/promises'); })); } -// { -// const s = new PassThrough(); -// pipeline(async function*() { -// await Promise.resolve(); -// yield 'hello'; -// yield 'world'; -// }, s, async function(source) { -// for await (const chunk of source) { -// throw new Error('kaboom'); -// } -// }, common.mustCall((err, val) => { -// assert.strictEqual(err.message, 'kaboom'); -// assert.strictEqual(s.destroyed, true); -// })); -// } +{ + const s = new PassThrough(); + pipeline(async function*() { + await Promise.resolve(); + yield 'hello'; + yield 'world'; + }, s, async function(source) { + for await (const chunk of source) { + throw new Error('kaboom'); + } + }, common.mustCall((err, val) => { + assert.strictEqual(err.message, 'kaboom'); + assert.strictEqual(s.destroyed, true); + })); +} { const s = new PassThrough();