Repository navigation
stream.pipeline does not invoke callback when error happens #39447
Description
Activity
- changed the title
[-]stream.pipeline does not invoke callback[/-][+]stream.pipeline does not invoke callback when error happens[/+]on Jul 19, 2021 - addedstreamIssues and PRs related to Node.js streams.Issues and PRs related to Node.js streams.
on Jul 19, 2021 @nodejs/streams
The problem is that
process.stdout()never gets closed.'use strict' const { Transform, Writable, pipeline } = require('stream') const w = new Writable({ write (chunk, enc, cb) { cb() } }) function createTransformStream (tf, context) { return new Transform({ readableObjectMode: true, writableObjectMode: true, transform (chunk, encoding, done) { tf(chunk, context, done) } }) } const ts = createTransformStream((chunk, _, done) => done(new Error('Artificial error'))) pipeline(ts, w, (err) => { if (err) console.log(err) console.log('done') }) console.log('run test') ts.write('test')
In theory, this should have been solved by #32373, but I guess there is something different from using a child_process and a tty.
@ronag wdyt?
Reacted by Benjamin Gruenbaum, Alex Yang, Zenquan and Kaique da SilvaReacted by Aleksey LitvinovReacted by Robert Nagy and Kaique da Silva- addedconfirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.good first issueIssues that are suitable for first-time contributors.Issues that are suitable for first-time contributors.
on Jul 19, 2021 Oh, makes sense. Thanks @mcollina for clarifying this issue for me.
@mcollina I have some questions...
Can i work on that issue?
Where is located the entry points for streams "Transformer"?
I can put the test on test folder and the execution happen because the existance of a mechanism for execution?I'm made some progress investigating the code base, but if it's possible to talk more about that could be helpful.
I have made a change who passes on tests with the case described by you @mcollina here some refs: https://github.com/ktfth/node/tree/fix/stream-pipeline-error-callback
You need to add a test for stdout. Look in https://github.com/nodejs/node/tree/master/test/pseudo-tty.
Reacted by Benjamin Gruenbaum, Kaique da Silva and Nilanshu V RajmaneIncluded another test with process.stdout, but looking the reference you shared @mcollina to create more tests
Do you have an hint to what I can search for to made a good test?
28 remaining items
- added a commit that references this issue
on Aug 5, 2021 After doing some work, I think this is not a bug. The following pass:
'use strict' const { Transform, pipeline } = require('stream') function createTransformStream (tf, context) { return new Transform({ readableObjectMode: true, writableObjectMode: true, transform (chunk, encoding, done) { tf(chunk, context, done) } }) } const ts = createTransformStream((chunk, _, done) => done(new Error('Artificial error'))) process.stdout.on('error', function () { process._rawDebug('error emitted') }) process.stdout.on('close', function () { process._rawDebug('close emitted') }) pipeline(ts, process.stdout, (err) => { if (err) process._rawDebug(err) process._rawDebug('done') }) console.log('run test') ts.write('test')
The reason why you do not see the output is that
process.stdoutis closed. Maybe we should print a warning in this case (or maybeconsole.log()should bypass it.Reacted by Aleksey LitvinovAfter doing some work, I think this is not a bug.
[...]
The reason why you do not see the output is that
process.stdoutis closed. Maybe we should print a warning in this case (or maybeconsole.log()should bypass it.According to #7606 (comment) stdio should never be closed
the actual file descriptor is never closed. However the stream object
process.stdoutcan be closed as it is a stream.
Otherwise the callback topipelinewould never be called.Reacted by Benjamin Gruenbaum and Aleksey LitvinovI understand and totally agree
the actual file descriptor is never closed. However the stream object
process.stdoutcan be closed as it is a stream.
Otherwise the callback topipelinewould never be called.Closing the stdio can have an unwanted results:
- If you run the code in the issue above in REPL you wouldn't see any character you type after that ran
- Loggers that use process.stdout would not output anything if it will close.
I'm sure there are more reasons, this is just at the top of my head.
I think we should fix the
pipelinerather than theprocess.stdout- added a commit that references this issue
on Aug 5, 2021 Here is an alternative way to fix this: #39670
Reacted by Aleksey Litvinov- added a commit that references this issue
on Aug 16, 2021 - added a commit that references this issue
on May 22, 2026
Version
v15.8.0
Platform
Darwin Alekseys-iMac.local 20.5.0 Darwin Kernel Version 20.5.0: Sat May 8 05:10:33 PDT 2021; root:xnu-7195.121.3~9/RELEASE_X86_64 x86_64
Subsystem
stream
What steps will reproduce the bug?
Run the following code:
How often does it reproduce? Is there a required condition?
all the time
What is the expected behavior?
I expect
pipelinecallback to be called with error argument. So I'll have the output like this:What do you see instead?
pipelinecallback is not called. Output that I have:Additional information
When I run mentioned code with
--inspect-brkflag — I can achieve expected behaviour in google chrome console. Steps:node --inspect-brk demo.jschrome://inspect/#devicesin chrome