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 <16024985+trivikr@users.noreply.github.com>
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
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. 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