From 48a15eb8f61f494fd55cfda4bbb371bad3e8cb35 Mon Sep 17 00:00:00 2001 From: Marvin ROGER Date: Sun, 20 Oct 2024 17:30:46 +0200 Subject: [PATCH 1/2] stream: propagate AbortSignal reason --- lib/internal/streams/pipeline.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/streams/pipeline.js b/lib/internal/streams/pipeline.js index 247a557686474e..60d050d54e5cdb 100644 --- a/lib/internal/streams/pipeline.js +++ b/lib/internal/streams/pipeline.js @@ -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; From ed0d894c3a634696f5f8bcaa0f6dfe74177c65e7 Mon Sep 17 00:00:00 2001 From: Marvin ROGER Date: Sun, 20 Oct 2024 17:58:47 +0200 Subject: [PATCH 2/2] test: check the pipeline AbortSignal reason is propagated --- test/parallel/test-stream-pipeline.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-stream-pipeline.js b/test/parallel/test-stream-pipeline.js index fc721c3a562b9e..2ee323a934606e 100644 --- a/test/parallel/test-stream-pipeline.js +++ b/test/parallel/test-stream-pipeline.js @@ -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);