stream: resume flow when an errored pipe destination is removed#64310
Open
MahinAnowar wants to merge 1 commit into
Open
stream: resume flow when an errored pipe destination is removed#64310MahinAnowar wants to merge 1 commit into
MahinAnowar wants to merge 1 commit into
Conversation
Collaborator
|
Review requested:
|
Collaborator
When a source is piped to multiple destinations and one destination errors synchronously in `_write()`, `write()` returns false without setting `needDrain` (since the "avoid unnecessary drain for sync stream" change). The pipe cleanup only re-invoked the source's drain handler when the destination still had `needDrain` set, so the errored destination was never removed from the source's `awaitDrainWriters` set. The source stayed paused forever and any remaining healthy destination stopped receiving data. Always invoke the drain handler during cleanup. `pipeOnDrain` only removes this destination from the awaiting-drain set and resumes the source once nothing else is awaiting a drain, so it is safe to call unconditionally and no-ops when this destination was not awaiting a drain. Fixes: nodejs#53185 Signed-off-by: Mahin Anowar <86069420+MahinAnowar@users.noreply.github.com>
b723522 to
683eddc
Compare
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.
Fixes: #53185
Problem
When a source is piped to two destinations and one destination errors synchronously in
_write(), the source stops flowing to the healthy destination as well. This is a regression from v20.10.0 (bisected to #50014 in the issue), where the healthy destination received all the data.Cause
After #50014 ("avoid unnecessary drain for sync stream"), a synchronous
write()to a destination that errors returnsfalsewithout settingneedDrain. On the readable side,pause()adds that destination tostate.awaitDrainWritersand pauses the source. When the errored destination unpipes,cleanup()only re-invokes the source's drain handler whendest._writableState.needDrainis set — which is now false for the sync-errored destination. So the dead destination is never removed fromawaitDrainWriters,pipeOnDrainnever sees an empty set, and the source stays paused, starving the healthy destination.Fix
Call the drain handler unconditionally in
cleanup().pipeOnDrainonly removes the given destination fromawaitDrainWritersand resumes the source once nothing else is awaiting a drain, so calling it is safe and no-ops when the destination wasn't awaiting a drain. This restores the pre-20.10 behavior (matching the direction @mcollina noted on the issue).Test
test/parallel/test-stream-pipe-multiple-destinations-error.jspipes a source to a synchronously-erroring destination and a healthy counting destination, writes two over-highWaterMark chunks, and asserts the healthy destination receives everything. It fails on currentmain(the source stalls and the healthy destination only gets the first chunk) and passes with this change.