stream: prevent enqueue after cancel in Readable.toWeb() - #64766
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #64766 +/- ##
==========================================
+ Coverage 90.14% 90.16% +0.01%
==========================================
Files 744 744
Lines 242518 242519 +1
Branches 45685 45691 +6
==========================================
+ Hits 218611 218660 +49
+ Misses 15396 15361 -35
+ Partials 8511 8498 -13
🚀 New features to boost your workflow:
|
3710995 to
28f4c68
Compare
|
Sorry, missclicked. Anyway, there were a few linting issues in test/parallel/test-webstreams-adapters-cancel-backpressure.js. I removed some trailing spaces on empty lines. I wrapped the I properly declared Commit message used I amended commit message from |
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.
Fixes: #64529