Skip to content

stream: propagate abort reason in share and broadcast#63358

Open
trivikr wants to merge 2 commits into
nodejs:mainfrom
trivikr:stream-iter-abort-signal
Open

stream: propagate abort reason in share and broadcast#63358
trivikr wants to merge 2 commits into
nodejs:mainfrom
trivikr:stream-iter-abort-signal

Conversation

@trivikr
Copy link
Copy Markdown
Member

@trivikr trivikr commented May 16, 2026

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

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 <[email protected]>
Assisted-by: openai:gpt-5.5
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/streams

@nodejs-github-bot nodejs-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 jasnell May 16, 2026 00:17
@trivikr trivikr self-assigned this May 16, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.06%. Comparing base (c0327d3) to head (bf6a9c3).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #63358      +/-   ##
==========================================
- Coverage   90.08%   90.06%   -0.03%     
==========================================
  Files         714      714              
  Lines      225516   225517       +1     
  Branches    42655    42646       -9     
==========================================
- Hits       203161   203104      -57     
- Misses      14136    14183      +47     
- Partials     8219     8230      +11     
Files with missing lines Coverage Δ
lib/internal/streams/iter/broadcast.js 85.32% <100.00%> (+0.65%) ⬆️
lib/internal/streams/iter/share.js 85.77% <100.00%> (+1.64%) ⬆️

... and 28 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.

@trivikr trivikr added the request-ci Add this label to start a Jenkins CI on a PR. label May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. request-ci Add this label to start a Jenkins CI on a PR. stream Issues 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

2 participants