mirror of
https://github.com/nodejs/node.git
synced 2026-11-30 11:55:44 -05:00
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 <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
1 parent
64cd3a6e95
commit
b8a7a75b19
2 files changed
+22
No files matched your search
@@ -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) {
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in new issue
Block a user