Skip to content

stream: propagate abort reason in share and broadcast - #63358

Merged
nodejs-github-bot merged 8 commits into
nodejs:mainfrom
trivikr:stream-iter-abort-signal
May 23, 2026
Merged

stream: propagate abort reason in share and broadcast#63358
nodejs-github-bot merged 8 commits into
nodejs:mainfrom
trivikr:stream-iter-abort-signal

Conversation

@trivikr

Copy link
Copy Markdown
Member

This updates broadcast({ signal }) and share(source, { signal }) to
propagate signal.reason when the signal aborts.

Previously, the abort handlers called cancel() with no reason. That
made waiting consumers observe clean iterator completion instead of
rejecting with the signal's abort reason, which is an AbortError for
AbortController.abort().

The Iterable Streams draft defines BroadcastOptions.signal and ShareOptions.signal,
and defines Broadcast.cancel(reason) such that consumers see an error when a reason
is provided and clean completion otherwise:

This change aligns broadcast() and share() with that behavior by calling
cancel(signal.reason) on abort. It also ensures pending share() consumers
that resume after cancellation rethrow the stored source error instead of
converting it back into clean completion.

Fixes: #63357


Assisted-by: openai:gpt-5.5

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/streams

@nodejs-github-botnodejs-github-bot added needs-ci PRs that need a full CI run. stream Issues and PRs related to the stream subsystem. labels May 16, 2026
@trivikr
trivikr requested a review from jasnellMay 16, 2026 00:17
@trivikrtrivikr self-assigned this May 16, 2026
@codecov

codecovBot commented May 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.13%. Comparing base (2f56cd2) to head (4236470).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@ Coverage Diff @@## main #63358 +/- ##
==========================================
- Coverage 90.17% 90.13% -0.05% 
==========================================
Files 718 718 Lines 227731 227923 +192 Branches 42768 42828 +60 ==========================================
+ Hits 205365 205430 +65 - Misses 14145 14277 +132 + Partials 8221 8216 -5 
Files with missing linesCoverage Δ
lib/internal/streams/iter/broadcast.js85.23% <100.00%> (+0.70%)⬆️
lib/internal/streams/iter/share.js85.84% <100.00%> (+1.72%)⬆️

... and 39 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@trivikrtrivikr added the request-ci Add this label to start a Jenkins CI on a PR. label May 16, 2026
@trivikr
trivikrforce-pushed the stream-iter-abort-signal branch from bf6a9c3 to 0b2f09fCompareMay 17, 2026 23:37
Comment threadtest/parallel/test-stream-iter-broadcast-from.js
Comment threadtest/parallel/test-stream-iter-share-async.js
@trivikr
trivikrforce-pushed the stream-iter-abort-signal branch from 0b2f09f to 357819aCompareMay 19, 2026 21:30
@trivikr
trivikr requested a review from aduh95May 20, 2026 06:40
@trivikrtrivikr removed their assignment May 21, 2026
trivikr added 5 commits May 21, 2026 22:36
Pass signal.reason to the multi-consumer cancel paths so signal abort
is reported as AbortError instead of clean iterator completion.
Also make detached share consumers rethrow a stored source error when
they resume after cancellation, preserving the abort reason for pending
pulls.
Fixes: nodejs#63357
Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: openai:gpt-5.5
@trivikr
trivikrforce-pushed the stream-iter-abort-signal branch from 7cd59d9 to 5ebe6edCompareMay 22, 2026 05:36
Comment threadlib/internal/streams/iter/broadcast.js Outdated
Comment threadlib/internal/streams/iter/share.js Outdated
Comment threadtest/parallel/test-stream-iter-share-async.js Outdated
Comment threadtest/parallel/test-stream-iter-share-async.js Outdated
@trivikr
trivikr requested review from aduh95 and jasnellMay 22, 2026 15:28
@trivikrtrivikr added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label May 22, 2026
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 22, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@trivikrtrivikr added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels May 23, 2026
@nodejs-github-botnodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label May 23, 2026
@nodejs-github-bot
nodejs-github-bot merged commit a7d5446 into nodejs:mainMay 23, 2026
87 of 89 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in a7d5446

@trivikr
trivikr deleted the stream-iter-abort-signal branch May 27, 2026 07:50
aduh95 pushed a commit that referenced this pull request May 27, 2026
Pass signal.reason to the multi-consumer cancel paths so signal abort
is reported as AbortError instead of clean iterator completion.
Also make detached share consumers rethrow a stored source error when
they resume after cancellation, preserving the abort reason for pending
pulls.
Fixes: #63357
Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: openai:gpt-5.5
PR-URL: #63358Fixes: #63357
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
aduh95 pushed a commit to aduh95/node that referenced this pull request Jul 30, 2026
Pass signal.reason to the multi-consumer cancel paths so signal abort
is reported as AbortError instead of clean iterator completion.
Also make detached share consumers rethrow a stored source error when
they resume after cancellation, preserving the abort reason for pending
pulls.
Fixes: nodejs#63357
Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: openai:gpt-5.5
PR-URL: nodejs#63358Fixes: nodejs#63357
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
aduh95 pushed a commit that referenced this pull request Aug 6, 2026
Pass signal.reason to the multi-consumer cancel paths so signal abort
is reported as AbortError instead of clean iterator completion.
Also make detached share consumers rethrow a stored source error when
they resume after cancellation, preserving the abort reason for pending
pulls.
Fixes: #63357
Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: openai:gpt-5.5
PR-URL: #63358
Backport-PR-URL: #64675Fixes: #63357
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.commit-queue-squashAdd this label to instruct the Commit Queue to squash all the PR commits into the first one.needs-ciPRs that need a full CI run.streamIssues and PRs related to the stream subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stream/iter: abort signal causes broadcast() and share() consumers to resolve EOF instead of rejecting

4 participants

@trivikr@nodejs-github-bot@jasnell@aduh95