stream: prevent enqueue after cancel in Readable.toWeb()#64766
Open
kairosci wants to merge 1 commit into
Open
Conversation
avivkeller
approved these changes
Jul 26, 2026
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request resolves an issue where converting a Node readable stream to a web stream using the toWeb method could result in an uncatchable exception when the stream is cancelled during a backpressure resume cycle. When the cancel method is invoked on the underlying source, the controller transitions to a closed state but the data listener remains attached to the source stream. Consequently, a scheduled flow tick may deliver an additional data event which triggers an invalid state error upon attempting to enqueue the chunk into the already closed controller. To fix this behavior structurally, a cancellation guard is added directly inside the data event listener to intercept and discard any incoming chunks once the stream has been marked as cancelled. A regression test is also included to ensure that disconnecting a pipeline under backpressure properly tears down the stream without throwing uncaught exceptions. Closes #64529