Repository navigation
pipeline leaves a hanging error handler #35452
Description
Activity
This is by design.
The docs say:
stream.pipeline() leaves dangling event listeners on the streams after the callback has been invoked. In the case of reuse of streams after failure, this can cause event listener leaks and swallowed errors.
This is by design.
Can this design be improved? Or is this a no?
Hmmm
/cc @nodejs/streams
I don’t think there is anything more to do here. Unless someone has suggestion?
@ronag I agree. Using pipeline() means letting pipeline() manage the lifetime of the streams, after which the streams are destroyed and should not be touched anymore.
Using pipeline() means letting pipeline() manage the lifetime of the streams
It does not. b.destroyed is false. So the readable side is still open. The fix is either to remove the hanging handler or destroy the end stream.
I missed that the last stream in the example is a duplex stream. Not sure how that should behave, because the readable side can't be consumed.
the readable side can't be consumed.
What do you mean?
If it were pipeline(readableStream, duplexStream, writableStream) then the readable side of duplexStream would be piped into writableStream. But if duplexStream is the last stream in the pipeline, then no one is reading from it.
If we swap the duplex stream in your example for a writable stream, then it does get destroyed:
const {pipeline, PassThrough, Writable} = require('stream')
const a = new PassThrough()
a.end('foobar')
const b = new Writable({
write (chunk, encoding, callback) {
callback()
}
})
pipeline(a, b, function (err) {
if (err) {
throw err
}
console.log(a.destroyed) // true
console.log(b.destroyed) // true
})But if duplexStream is the last stream in the pipeline, then no one is reading from it.
You don't know. It's readable so it's not destroyed. Something can be reading it a tick later.
3 remaining items
Sure, would love to.
@szmarczak any updates here?
Sorry, totally forgot about this one. Will sketch something in a few hours.
Sorry, totally forgot about this one. Will sketch something in a few hours.
Count on me to help! @szmarczak
@joaoofreitas awesome! Feel free to send a PR first and I'll chime in and let you know my thoughts :D
If this is still work in progress I'd be happy to help
Sure thing!
@Heikrana this might end up a bit too hard. Maybe try something easier first? It's one of the hardest part of Node.
@Heikrana this might end up a bit too hard. Maybe try something easier first? It's one of the hardest part of Node.
Okay, I see your point. I've been trying to understand the stream API and yeah, it's a bit confusing.
I'd still try to solve this issue (since no one else is working on it).
But in the meantime, can you suggest me some resources (which would help me contribute to NodeJS) or another issue which might be more of my level. I really want to be part of this community :)
Linux SZM-DESKTOP 4.19.104-microsoft-standard #1 SMP Wed Feb 19 06:37:35 UTC 2020 x86_64 x86_64 x86_64 GNU/LinuxWhat steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
Always.
What is the expected behavior?
What do you see instead?
/cc @ronag