Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/internal/streams/iter/pull.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-stream-iter-pull-async.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -409,6 +426,7 @@ async function testTransformOptionsNotShared() {
testPullStatelessTransformFlush(),
testPullConsecutiveStatelessTransformFlush(),
testPullStatelessTransformFlushError(),
testPullSignalAbortDuringAsyncFlush(),
testPullWithSyncSource(),
testPullStringSource(),
testTransformReturnsSingleUint8Array(),
Expand Down
Loading