Skip to content

stream: fix ERR_INVALID_STATE when cancelling Readable.toWeb()#62773

Open
richardscarrott wants to merge 1 commit intonodejs:mainfrom
richardscarrott:fix/readable-to-web-cancel-race
Open

stream: fix ERR_INVALID_STATE when cancelling Readable.toWeb()#62773
richardscarrott wants to merge 1 commit intonodejs:mainfrom
richardscarrott:fix/readable-to-web-cancel-race

Conversation

@richardscarrott
Copy link
Copy Markdown

When a web ReadableStream returned by Readable.toWeb() is cancelled while the underlying Readable is actively producing data, a pending onData callback can still fire after the controller has been closed and attempt to enqueue a chunk, throwing ERR_INVALID_STATE.

Check wasCanceled in the onData handler and return early to avoid calling controller.enqueue() on a closed controller.

Refs: #54205

When a web ReadableStream returned by Readable.toWeb() is cancelled
while the underlying Readable is actively producing data, a pending
onData callback can still fire after the controller has been closed
and attempt to enqueue a chunk, throwing ERR_INVALID_STATE.

Check wasCanceled in the onData handler and return early to avoid
calling controller.enqueue() on a closed controller.

Refs: nodejs#54205
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. web streams labels Apr 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. web streams

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants