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
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.69%. Comparing base (ed05549) to head (96e546b).
⚠️ Report is 13 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #62773   +/-   ##
=======================================
  Coverage   89.69%   89.69%           
=======================================
  Files         706      706           
  Lines      218127   218144   +17     
  Branches    41734    41743    +9     
=======================================
+ Hits       195651   195669   +18     
+ Misses      14400    14396    -4     
- Partials     8076     8079    +3     
Files with missing lines Coverage Δ
lib/internal/webstreams/adapters.js 86.61% <100.00%> (+0.01%) ⬆️

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

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.

3 participants