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: ensure factory signals remain active through closing · nodejs/node@2b31b0d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • stream_iter.md
  • lib/internal/streams/iter
    • push.js
  • test/parallel
    • test-stream-iter-push-writer.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
+3-1Lines changed: 3 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,9 @@ added: v24.20.0
765765
**Default:** `16384`.
766766
* `backpressure` {string} Backpressure policy: `'strict'`, `'unbounded'`,
767767
`'drop-oldest'`, or `'drop-newest'`. **Default:** `'strict'`.
768-
* `signal` {AbortSignal} Abort the stream.
768+
* `signal` {AbortSignal} Abort the stream. The signal remains active while
769+
buffered data drains after `writer.end()`; aborting during that time fails
770+
the writer and rejects the pending `end()` promise.
769771
* Returns: {Object}
770772
* `writer` {Writable} The writer side.
771773
* `readable` {AsyncIterable} whose chunks fulfill with {Uint8Array\[]}
Collapse file

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

Copy file name to clipboardExpand all lines: lib/internal/streams/iter/push.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,14 @@ class PushQueue {
331331
return this.#bytesWritten; // Idempotent
332332
}
333333

334-
this.#cleanup();
335334
this.#rejectPendingWrites(
336335
new ERR_INVALID_STATE.TypeError('Writer closed'));
337336
this.#resolvePendingDrains(false);
338337

339338
// If buffer is empty, close immediately
340339
if (this.#slots.length === 0) {
341340
this.#writerState = 'closed';
341+
this.#cleanup();
342342
this.#resolvePendingReads();
343343
return this.#bytesWritten;
344344
}
@@ -356,6 +356,7 @@ class PushQueue {
356356
endDrained() {
357357
if (this.#writerState !== 'closing') return;
358358
this.#writerState = 'closed';
359+
this.#cleanup();
359360
if (this.#pendingEnd) {
360361
this.#pendingEnd.resolve(this.#bytesWritten);
361362
this.#pendingEnd = null;
Collapse file

‎test/parallel/test-stream-iter-push-writer.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-stream-iter-push-writer.js
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,21 @@ async function testEndSignalAbortWhileDraining() {
294294
assert.strictEqual(await completedEnd, 5);
295295
}
296296

297+
async function testFactorySignalAbortWhileDraining() {
298+
const controller = new AbortController();
299+
const reason = new Error('stream aborted while draining');
300+
const { writer, readable } = push({ signal: controller.signal });
301+
302+
writer.writeSync('hello');
303+
const end = writer.end();
304+
const endRejected = assert.rejects(end, (error) => error === reason);
305+
controller.abort(reason);
306+
307+
await endRejected;
308+
await assert.rejects(text(readable), (error) => error === reason);
309+
await assert.rejects(writer.end(), (error) => error === reason);
310+
}
311+
297312
async function testEndAfterEndSyncWaitsForDrain() {
298313
const { writer, readable } = push();
299314
writer.writeSync('hello');
@@ -603,6 +618,7 @@ Promise.all([
603618
testEndAsyncReturnValue(),
604619
testEndWithPreAbortedSignal(),
605620
testEndSignalAbortWhileDraining(),
621+
testFactorySignalAbortWhileDraining(),
606622
testEndAfterEndSyncWaitsForDrain(),
607623
testWriteUint8Array(),
608624
testOndrainWaitsForDrain(),

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.