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: update ShareImpl to retain factory abort listener · nodejs/node@3407386

File tree

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

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

Copy file name to clipboardExpand all lines: lib/internal/streams/iter/share.js
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,9 @@ class ShareImpl {
432432
this.#sourceError = error;
433433
this.#sourceExhausted = true;
434434
} finally {
435-
if (this.#sourceExhausted) this.#cleanupFactorySignal();
435+
if (this.#sourceExhausted && this.#consumers.size === 0) {
436+
this.#cleanupFactorySignal();
437+
}
436438
this.#pulling = false;
437439
for (let i = 0; i < this.#pullWaiters.length; i++) {
438440
this.#pullWaiters[i]();
@@ -496,7 +498,11 @@ class ShareImpl {
496498

497499
#deleteConsumer(consumer) {
498500
if (this.#consumers.delete(consumer)) {
499-
return this.#deleteConsumerFromMin(consumer);
501+
const shouldTrimBuffer = this.#deleteConsumerFromMin(consumer);
502+
if (this.#sourceExhausted && this.#consumers.size === 0) {
503+
this.#cleanupFactorySignal();
504+
}
505+
return shouldTrimBuffer;
500506
}
501507
return false;
502508
}
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-stream-iter-factory-signal.js
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,22 @@ async function testShareSignalLifetime() {
6262
assert.strictEqual(abortListenerCount(controller.signal), 0);
6363
}
6464

65+
async function testShareSignalLifetimeWithSlowConsumer() {
66+
const controller = new AbortController();
67+
const reason = new Error('aborted');
68+
const shared = share('x', { signal: controller.signal });
69+
const fast = shared.pull()[Symbol.asyncIterator]();
70+
const slow = shared.pull()[Symbol.asyncIterator]();
71+
72+
assert.strictEqual((await fast.next()).done, false);
73+
assert.strictEqual((await fast.next()).done, true);
74+
assert.strictEqual(abortListenerCount(controller.signal), 1);
75+
76+
controller.abort(reason);
77+
await assert.rejects(slow.next(), (error) => error === reason);
78+
assert.strictEqual(abortListenerCount(controller.signal), 0);
79+
}
80+
6581
async function testDuplexSignalLifetime() {
6682
const controller = new AbortController();
6783
const [channelA, channelB] = duplex({ signal: controller.signal });
@@ -80,5 +96,6 @@ Promise.all([
8096
testPushSignalLifetime(),
8197
testBroadcastSignalLifetime(),
8298
testShareSignalLifetime(),
99+
testShareSignalLifetimeWithSlowConsumer(),
83100
testDuplexSignalLifetime(),
84101
]).then(common.mustCall());

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.