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 aduh95 committed Oct 23, 2024
1 parent bbd5318 commit 6764273
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 @@ -203,7 +203,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 @@ -1344,12 +1344,13 @@ tmpdir.refresh();

{
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 @@ -1362,6 +1363,7 @@ tmpdir.refresh();
});
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 6764273

Please sign in to comment.