Repository navigation
stream.pipeline doesn't wait for 'close' on error #51540
Description
Activity
- addedstreamIssues and PRs related to Node.js streams.Issues and PRs related to Node.js streams.
on Apr 28, 2024 Hi, I am trying to get a bit more context here, do you expect the
closeevent onWritablestream happens before the callback is being called?yes. from all that I've seen, I do think the intention of
stream.pipelinewas to wait for the Writable to finish closing before calling the callback. there's thisfinishCountcode that's meant to keep track of everything closing, but it's getting decremented way more times than the code that sets up the initial count expectsI do think the intention of stream.pipeline was to wait for the Writable to finish closing before calling the callback
I think you are right on this one. I have taken some time to dig, what I found it out is that because theERR_METHOD_NOT_IMPLEMENTEDerror that messed up thefinishCount(I used the debugger but you can just log the err here and I think you will understand what I mean.If you implement theread{}function in the Readable stream then it is the behaviour you expected, or if you can take a look the patch I made here and let me know if it makes sense or not 👀Thanks a lot for narrowing down the directions, if the fix is good are you happy for me to add you as a co-author on the PR?
EDIT: Sorry, I think my fix was incorrect!
IIRC the first error wins. The pipeline is "done" and all streams destroyed when the first error occurs.
so if I understand correctly "done" here means all the streams have been destroyed but not guaranteed closed?
Yes.
Reacted by jakecastelliabout read not implemented: that was unintentional. wasn't
new stream.Readable()the way to make readable stream where you'd call .push(chunk) and .push(null)? it should use the default read implementation that waits for something to call push.I was using the closed property to check that the stream was destroyed, done being destroyed, specifically. now that I look more into the streams API, I see that you can configure streams not to emit a close event when you destroy them. that complicates things.
for longer pipelines, it looks like the current logic would wait for about half of the streams to emit error before calling the callback, and that also feels weird.
- added a commit that references this issue
on Jun 27, 2024 - added 2 commits that reference this issue
on Jul 12, 2024
Version
v20.11.0
Platform
Linux cs-63018580108-ephemeral-4kum 6.1.58+ #1 SMP PREEMPT_DYNAMIC Sat Dec 30 15:31:26 UTC 2023 x86_64 GNU/Linux
Subsystem
internal/streams/pipeline
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
always
What is the expected behavior? Why is that the expected behavior?
dst.closed=true
maybe? #32158 sounds like it should
What do you see instead?
Additional information
I notice that this
finishCountcountdown goes from 2 down to -3.