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: pre-aborted pipeTo now applies dest failure handling · nodejs/node@037c07a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • stream_iter.md
  • lib/internal/streams/iter
    • pull.js
  • test/parallel
    • test-stream-iter-pipeto-signal.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/stream_iter.md‎

Copy file name to clipboardExpand all lines: doc/api/stream_iter.md
+2-1Lines changed: 2 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,8 @@ added: v25.9.0
613613
* `...transforms` {Function|Object} Zero or more transforms to apply.
614614
* `writer` {Object} Destination with `write(chunk)` method.
615615
* `options` {Object}
616-
* `signal` {AbortSignal} Abort the pipeline.
616+
* `signal` {AbortSignal} Abort the pipeline. Aborting fails the destination
617+
writer unless `preventFail` is `true`.
617618
* `preventClose` {boolean} If `true`, do not call `writer.end()` when
618619
the source ends. **Default:** `false`.
619620
* `preventFail` {boolean} If `true`, do not call `writer.fail()` on
Collapse file

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

Copy file name to clipboardExpand all lines: lib/internal/streams/iter/pull.js
+13-5Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,8 +1054,18 @@ async function pipeTo(source, ...args) {
10541054

10551055
const signal = options?.signal;
10561056

1057-
// Check for abort
1058-
signal?.throwIfAborted();
1057+
function failWriter(error) {
1058+
if (!options?.preventFail) {
1059+
writer.fail?.(wrapError(error));
1060+
}
1061+
}
1062+
1063+
try {
1064+
signal?.throwIfAborted();
1065+
} catch (error) {
1066+
failWriter(error);
1067+
throw error;
1068+
}
10591069

10601070
const hasWriteSync = typeof writer.writeSync === 'function';
10611071
const useSyncIterableFastPath =
@@ -1192,9 +1202,7 @@ async function pipeTo(source, ...args) {
11921202
}
11931203
}
11941204
} catch (error) {
1195-
if (!options?.preventFail) {
1196-
writer.fail?.(wrapError(error));
1197-
}
1205+
failWriter(error);
11981206
throw error;
11991207
}
12001208

Collapse file

‎test/parallel/test-stream-iter-pipeto-signal.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-stream-iter-pipeto-signal.js
+47Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,51 @@ const assert = require('assert');
99
const { setTimeout } = require('timers/promises');
1010
const { pipeTo, from } = require('stream/iter');
1111

12+
async function testPipeToPreAbortedSignalFailsWriter() {
13+
const reason = new Error('already aborted');
14+
let sourceTouched = false;
15+
const source = {
16+
[Symbol.asyncIterator]() {
17+
sourceTouched = true;
18+
return {};
19+
},
20+
};
21+
const writer = {
22+
write: common.mustNotCall(),
23+
fail: common.mustCall((error) => assert.strictEqual(error, reason)),
24+
};
25+
26+
await assert.rejects(
27+
pipeTo(source, writer, { signal: AbortSignal.abort(reason) }),
28+
(error) => error === reason,
29+
);
30+
assert.strictEqual(sourceTouched, false);
31+
}
32+
33+
async function testPipeToPreAbortedSignalPreventFail() {
34+
const reason = new Error('already aborted');
35+
let sourceTouched = false;
36+
const source = {
37+
[Symbol.asyncIterator]() {
38+
sourceTouched = true;
39+
return {};
40+
},
41+
};
42+
const writer = {
43+
write: common.mustNotCall(),
44+
fail: common.mustNotCall(),
45+
};
46+
47+
await assert.rejects(
48+
pipeTo(source, writer, {
49+
signal: AbortSignal.abort(reason),
50+
preventFail: true,
51+
}),
52+
(error) => error === reason,
53+
);
54+
assert.strictEqual(sourceTouched, false);
55+
}
56+
1257
// pipeTo with live signal, no transforms — abort mid-stream
1358
async function testPipeToLiveSignalNoTransforms() {
1459
const ac = new AbortController();
@@ -116,6 +161,8 @@ async function testPipeToLiveSignalWithTransformsCompletes() {
116161
}
117162

118163
Promise.all([
164+
testPipeToPreAbortedSignalFailsWriter(),
165+
testPipeToPreAbortedSignalPreventFail(),
119166
testPipeToLiveSignalNoTransforms(),
120167
testPipeToLiveSignalNoTransformsPendingNext(),
121168
testPipeToLiveSignalWithTransforms(),

0 commit comments

Comments
0 (0)
You are visitor 01402792 — 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.