stream: fix ERR_INVALID_STATE when cancelling Readable.toWeb() · nodejs/node@f8737b8 · GitHub
Skip to content

Commit f8737b8

Browse files
richardscarrottaduh95
authored andcommitted
stream: fix ERR_INVALID_STATE when cancelling Readable.toWeb()
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 Signed-off-by: Richard Scarrott <riscarrott@googlemail.com> PR-URL: #62773 Reviewed-By: Xuguang Mei <meixuguang@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 7011764 commit f8737b8

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

‎lib/internal/webstreams/adapters.js‎

Lines changed: 1 addition & 0 deletions

‎test/parallel/test-stream-readable-to-web-termination.js‎

Lines changed: 22 additions & 0 deletions

0 commit comments

Comments
 (0)