Skip to content

stream: fix addAbortSignal() for web streams#62450

Draft
ikeyan wants to merge 2 commits intonodejs:mainfrom
ikeyan:fix-k-controller-error-function
Draft

stream: fix addAbortSignal() for web streams#62450
ikeyan wants to merge 2 commits intonodejs:mainfrom
ikeyan:fix-k-controller-error-function

Conversation

@ikeyan
Copy link
Copy Markdown
Contributor

@ikeyan ikeyan commented Mar 27, 2026

This fixes stream.addAbortSignal() for web streams.

addAbortSignal() used kControllerErrorFunction, which mixed stream erroring
with abort handling.

For readable byte streams, ReadableByteStreamController left the default no-op
hook in place, so addAbortSignal() could not abort the stream.

For writable streams, WritableStreamDefaultController wired the hook to
controller.error(), so the stream became errored but
controller.signal.aborted stayed false.

This replaces kControllerErrorFunction with kControllerAbortFunction and
wires each controller to the internal operation that matches its abort path:

  • ReadableStreamDefaultController uses
    readableStreamDefaultControllerError()
  • ReadableByteStreamController uses
    readableByteStreamControllerError()
  • WritableStreamDefaultController uses writableStreamAbort()

The updated test covers addAbortSignal() on readable byte streams, aborts
that race with pending pulls, writable abort signal state, and readable and
writable controllers with overridden public methods.

@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. web streams labels Mar 27, 2026
Comment on lines +1325 to +1327
stream[kControllerAbortFunction] = (reason) => {
setPromiseHandled(writableStreamAbort(stream, reason));
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slightly off-topic: should we make this a class method instead? For WritableStream, we could do:

class WritableStream {
  [kControllerAbortFunction](reason) {
    setPromiseHandled(writableStreamAbort(this, reason));
  }
}

For ReadableStream, the method could check the type of this[kState].controller and then call either readableStreamDefaultControllerError or readableByteStreamControllerError.

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. web streams

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants