From b8a7a75b19150f305a7639ff05c7853fb3d80e2a Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Tue, 18 Aug 2026 22:36:15 -0700 Subject: [PATCH] stream: reject pull on signal abort during flush An asynchronous transform can abort the pipeline while its final flush resolves to null. With no final batch yielded, the pipeline previously completed without observing the abort. Check the signal after transform iteration completes so the consumer rejects with the abort reason. Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: codex:gpt-5.6-sol PR-URL: https://github.com/nodejs/node/pull/65346 Fixes: https://github.com/nodejs/node/issues/65345 Reviewed-By: James M Snell Reviewed-By: Antoine du Hamel --- lib/internal/streams/iter/pull.js | 4 ++++ test/parallel/test-stream-iter-pull-async.js | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/internal/streams/iter/pull.js b/lib/internal/streams/iter/pull.js index c546e70ad96..d75a175443d 100644 --- a/lib/internal/streams/iter/pull.js +++ b/lib/internal/streams/iter/pull.js @@ -764,6 +764,10 @@ async function* createAsyncPipeline(source, transforms, signal) { controller.signal.throwIfAborted(); yield batch; } + // A transform can abort while completing without producing a final batch, + // for example when an async flush resolves to null. In that case the loop + // body has no opportunity to observe the abort. + controller.signal.throwIfAborted(); completed = true; } catch (error) { if (!controller.signal.aborted) { diff --git a/test/parallel/test-stream-iter-pull-async.js b/test/parallel/test-stream-iter-pull-async.js index 6fa3192e585..3159b718f27 100644 --- a/test/parallel/test-stream-iter-pull-async.js +++ b/test/parallel/test-stream-iter-pull-async.js @@ -295,6 +295,23 @@ async function testPullStatelessTransformFlushError() { }, { message: 'async flush boom' }); } +// An abort during an async flush must not be swallowed when the flush resolves +// to null and therefore produces no final batch. +async function testPullSignalAbortDuringAsyncFlush() { + const ac = new AbortController(); + const reason = new Error('aborted during flush'); + const transform = async (chunks) => { + if (chunks !== null) return chunks; + ac.abort(reason); + return null; + }; + + await assert.rejects( + () => text(pull(from('x'), transform, { signal: ac.signal })), + (error) => error === reason, + ); +} + // Pull with a sync iterable source (not async) async function testPullWithSyncSource() { function* gen() { @@ -409,6 +426,7 @@ async function testTransformOptionsNotShared() { testPullStatelessTransformFlush(), testPullConsecutiveStatelessTransformFlush(), testPullStatelessTransformFlushError(), + testPullSignalAbortDuringAsyncFlush(), testPullWithSyncSource(), testPullStringSource(), testTransformReturnsSingleUint8Array(),