Skip to content

Commit 6764273

Browse files
marvinrogeraduh95
authored andcommittedOct 23, 2024
stream: propagate AbortSignal reason
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>
1 parent bbd5318 commit 6764273

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed
 

‎lib/internal/streams/pipeline.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ function pipelineImpl(streams, callback, opts) {
203203
validateAbortSignal(outerSignal, 'options.signal');
204204

205205
function abort() {
206-
finishImpl(new AbortError());
206+
finishImpl(new AbortError(undefined, { cause: outerSignal?.reason }));
207207
}
208208

209209
addAbortListener ??= require('internal/events/abort_listener').addAbortListener;

‎test/parallel/test-stream-pipeline.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1344,12 +1344,13 @@ tmpdir.refresh();
13441344

13451345
{
13461346
const ac = new AbortController();
1347+
const reason = new Error('Reason');
13471348
const r = Readable.from(async function* () {
13481349
for (let i = 0; i < 10; i++) {
13491350
await Promise.resolve();
13501351
yield String(i);
13511352
if (i === 5) {
1352-
ac.abort();
1353+
ac.abort(reason);
13531354
}
13541355
}
13551356
}());
@@ -1362,6 +1363,7 @@ tmpdir.refresh();
13621363
});
13631364
const cb = common.mustCall((err) => {
13641365
assert.strictEqual(err.name, 'AbortError');
1366+
assert.strictEqual(err.cause, reason);
13651367
assert.strictEqual(res, '012345');
13661368
assert.strictEqual(w.destroyed, true);
13671369
assert.strictEqual(r.destroyed, true);

0 commit comments

Comments
 (0)