stream: propagate AbortSignal reason

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Marvin ROGER 2024-10-22 18:14:02 +02:00 committed by GitHub
parent 603e55d94d
commit 4a00f9a1c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 2 deletions

View File

@ -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;

View File

@ -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);
}
}
}());
@ -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);