Skip to content

Commit

Permalink
stream: propagate AbortSignal reason
Browse files Browse the repository at this point in the history
PR-URL: #55473
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Robert Nagy <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: LiviaMedeiros <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Jake Yuesong Li <[email protected]>
  • Loading branch information
marvinroger authored and ruyadorno committed Nov 27, 2024
1 parent 15dd43d commit 8f59c41
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/internal/streams/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ function pipelineImpl(streams, callback, opts) {
validateAbortSignal(outerSignal, 'options.signal');

function abort() {
finishImpl(new AbortError());
finishImpl(new AbortError(undefined, { cause: outerSignal?.reason }));
}

addAbortListener ??= require('internal/events/abort_listener').addAbortListener;
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-stream-pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -1331,12 +1331,13 @@ const tsp = require('timers/promises');

{
const ac = new AbortController();
const reason = new Error('Reason');
const r = Readable.from(async function* () {
for (let i = 0; i < 10; i++) {
await Promise.resolve();
yield String(i);
if (i === 5) {
ac.abort();
ac.abort(reason);
}
}
}());
Expand All @@ -1349,6 +1350,7 @@ const tsp = require('timers/promises');
});
const cb = common.mustCall((err) => {
assert.strictEqual(err.name, 'AbortError');
assert.strictEqual(err.cause, reason);
assert.strictEqual(res, '012345');
assert.strictEqual(w.destroyed, true);
assert.strictEqual(r.destroyed, true);
Expand Down

0 comments on commit 8f59c41

Please sign in to comment.