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 <yagiz@nizipli.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
  • 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.