Repository navigation
doc: Piping multiple streams to the same Writable stream might not end #36544
Description
Activity
- addeddocIssues and PRs related to Node.js documentation.Issues and PRs related to Node.js documentation.
on Dec 16, 2020 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.
A simple solution would be to add a drain listener on dest after pausing src, like so: https://gist.github.com/HomerSp/07ec63dacf49aac5f55a62b7c09dc313Maybe 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
ondatahandler which will never get invoked since it's paused.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');
- addedconfirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.streamIssues and PRs related to Node.js streams.Issues and PRs related to Node.js streams.and removeddocIssues and PRs related to Node.js documentation.Issues and PRs related to Node.js documentation.
on Dec 18, 2020 @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.
- added a commit that references this issue
on Dec 21, 2020 - added a commit that references this issue
on May 1, 2021 - added a commit that references this issue
on May 22, 2026
📗 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.writableNeedDrainbefore piping a Readable stream?submit a pull request.