-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
doc: Piping multiple streams to the same Writable stream might not end #36544
Comments
This isn't really a problem with the documentation I would say, it seems to be caused by a bug introduced in #35348, lib/internal/streams/readable.js, that causes a pipe to be paused initially when the writable buffer needs draining. The problem is that the readable is just never resumed so it gets stuck and fails. Maybe this is supposed to be done automatically, but it just isn't? I can't see anything related to this though, so I'm not sure. |
Yea. It's a bug. The drain handler is added lazily in the The fix should probably be something like: index a004ce20d0..1afa3a2b29 100644
--- a/lib/internal/streams/readable.js
+++ b/lib/internal/streams/readable.js
@@ -794,6 +794,8 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
if (dest.writableNeedDrain === true) {
if (state.flowing) {
src.pause();
+ ondrain = pipeOnDrain(src, dest);
+ dest.on('drain', ondrain);
}
} else if (!state.flowing) {
debug('pipe resume'); |
This comment has been minimized.
This comment has been minimized.
@weedz do you have a minimal repro we could use as a basis for a test? |
@ronag Thanks, that also looks to work. I'll write up a small test, though it is a bit annoying since it's pretty random when it'll happen. Piping a bunch of different sources one after the other should trigger it eventually though. |
Opened PR. Still lacking tests though. #36563 |
@HomerSp I think it's enough to bring dst to need drain state and then pipe an additional readable. |
📗 API Reference Docs Problem
Location
Section of the site where the content exists
Affected URL(s):
Description
Concise explanation of the problem
The documentation for
readable.pipe()
reads:So when we open a Writable stream and then pipe multiple Readable streams into this Writable stream; the stream becomes full/congested and needs to drain but then we pipe more Readable streams into this stream. This seems to sometimes cause a Readable stream to not end and thus does not pipe its data to the Writable stream.
Bug in electron/asar explaining the issue electron/asar#210.
Since electron/asar does this in basically a
for await
-loop, we get stuck waiting for a Readable stream which never ends.Is this expected behavior when piping multiple Readable streams into one Writable stream? Should one check
writable.writableNeedDrain
before piping a Readable stream?submit a pull request.
The text was updated successfully, but these errors were encountered: