GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — stream: reject pull on signal abort during flush · nodejs/node@a9dc50d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/streams/iter
    • pull.js
  • test/parallel
    • test-stream-iter-pull-async.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/streams/iter/pull.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/iter/pull.js
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,10 @@ async function* createAsyncPipeline(source, transforms, signal) {
764764
controller.signal.throwIfAborted();
765765
yield batch;
766766
}
767+
// A transform can abort while completing without producing a final batch,
768+
// for example when an async flush resolves to null. In that case the loop
769+
// body has no opportunity to observe the abort.
770+
controller.signal.throwIfAborted();
767771
completed = true;
768772
} catch (error) {
769773
if (!controller.signal.aborted) {
Collapse file

‎test/parallel/test-stream-iter-pull-async.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-stream-iter-pull-async.js
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,23 @@ async function testPullStatelessTransformFlushError() {
295295
}, { message: 'async flush boom' });
296296
}
297297

298+
// An abort during an async flush must not be swallowed when the flush resolves
299+
// to null and therefore produces no final batch.
300+
async function testPullSignalAbortDuringAsyncFlush() {
301+
const ac = new AbortController();
302+
const reason = new Error('aborted during flush');
303+
const transform = async (chunks) => {
304+
if (chunks !== null) return chunks;
305+
ac.abort(reason);
306+
return null;
307+
};
308+
309+
await assert.rejects(
310+
() => text(pull(from('x'), transform, { signal: ac.signal })),
311+
(error) => error === reason,
312+
);
313+
}
314+
298315
// Pull with a sync iterable source (not async)
299316
async function testPullWithSyncSource() {
300317
function* gen() {
@@ -409,6 +426,7 @@ async function testTransformOptionsNotShared() {
409426
testPullStatelessTransformFlush(),
410427
testPullConsecutiveStatelessTransformFlush(),
411428
testPullStatelessTransformFlushError(),
429+
testPullSignalAbortDuringAsyncFlush(),
412430
testPullWithSyncSource(),
413431
testPullStringSource(),
414432
testTransformReturnsSingleUint8Array(),

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.