-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Piping twice to same stream then unpiping loses data #12718
Comments
I’m not sure, what would you expect to be the result of piping twice? Having all output of the source stream duplicated? That might lead to odd behaviour because streams don’t guarantee that the chunk boundaries stay the same, so unless you’re in object mode you might end up with non-deterministic behaviour, I think. |
Presumably, they're expecting either to reduce the Alternatively, to document that passing through to the same output twice produces non-deterministic behavior and is not supported. I'd probably go for the latter, but I'd like to see a motivating example for piping to the same output twice from a passthrough stream. |
PR for fixing: #12746 |
Fix the uncommon situation when a readable stream is piped twice into the same destination stream, and then unpiped once. Previously, the `unpipe` event handlers weren’t able to tell whether they were corresponding to the “right” conceptual pipe that was being removed; this fixes this by adding a counter to the `unpipe` event handler and only removing a single piping destination at most. Fixes: nodejs#12718
Fix the uncommon situation when a readable stream is piped twice into the same destination stream, and then unpiped once. Previously, the `unpipe` event handlers weren’t able to tell whether they were corresponding to the “right” conceptual pipe that was being removed; this fixes this by adding a counter to the `unpipe` event handler and only removing a single piping destination at most. Fixes: nodejs#12718 PR-URL: nodejs#12746 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Fix the uncommon situation when a readable stream is piped twice into the same destination stream, and then unpiped once. Previously, the `unpipe` event handlers weren’t able to tell whether they were corresponding to the “right” conceptual pipe that was being removed; this fixes this by adding a counter to the `unpipe` event handler and only removing a single piping destination at most. Fixes: #12718 PR-URL: #12746 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Piping twice to one single destination, and then unpiping once, has unexpected consequences. See the below code example.
If the intended behavior of unpiping once is to leave one destination in place, the data listener for that destination must be retained, so that our writable will keep receiving data.
Otherwise, I assume the intended behavior of unpiping once is to remove all pipes to the
same destination, (and pausing the stream when there are no remaining pipes).
If it's invalid to pipe twice to one destination, the documentation should say so and/or the program should crash.
The text was updated successfully, but these errors were encountered: