You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Stream.pipeline doesn't report failures if process.stdout is in the pipeline. #26550
Below is a simple example of a pipeline starting with a Readable, Transform, and then process.stdout. Failures in the Transform do not get reported by Stream.pipeline.
const { Transform, Readable, pipeline } = require('stream')
const reader = new Readable({
read(size) { this.push("foo") }
})
let count = 0;
const transform = new Transform({
transform(chunk, enc, cb) {
if (count++ >= 5)
this.emit("error", new Error("this-error-gets-hidden"))
else
cb(null, count.toString() + "\n")
}
})
pipeline(
reader,
transform,
process.stdout,
e => e ? console.error(e) : console.log("done")
)
The error that is emitted never shows up in the pipeline's callback. The pipeline does stop on the 5th iteration as expected, but the error gets gobbled up somehow. If process.stdout is removed from the pipeline, the error is displayed as expected.
Interestingly, the following works as expected:
pipeline(
reader,
transform,
e => e ? console.error(e) : console.log("done")
).pipe(
process.stdout
)
changed the title [-]Stream.pipeline doesn't report failures if process.stdout in the pipeline.[/-][+]Stream.pipeline doesn't report failures if process.stdout is in the pipeline.[/+]on Mar 9, 2019
The problem was caused by net.Socket having set emitClose: false because it was emitted its own event in _destroy(), and stdio.js was overriding _destroy without emitting 'close'. That PR fixes that.
On the other hand, maybe the default of trying to close the last stream is OK, and for those specials cases (like stdout) where its not desirable, the workaround is pretty simple.
I do not think I can help without a full repro of the problem you are experiencing. Can you open a new issue with a way to reproduce and tag me? Thanks
Activity
[-]Stream.pipeline doesn't report failures if process.stdout in the pipeline.[/-][+]Stream.pipeline doesn't report failures if process.stdout is in the pipeline.[/+]himself65 commentedon Mar 10, 2019
you can handle the error by yourself to fix it
himself65 commentedon Mar 10, 2019
I found that
onerrorhandler only just destroy itself and not to deliver the error message 😕node/lib/_stream_readable.js
Lines 715 to 721 in 6e81a95
bnoordhuis commentedon Mar 12, 2019
process.stdoutactually ends up with two'error'listeners, the other one being:node/lib/internal/streams/end-of-stream.js
Lines 52 to 54 in 6e81a95
I speculate
errorOrDestroy()is never actually called.mcollina commentedon Mar 15, 2019
I don't think this is a bug in
pipeline, but rather innode/lib/internal/fs/sync_write_stream.js
Lines 27 to 36 in 6f77af5
cc @tadjik1
tadjik1 commentedon Mar 15, 2019
@mcollina my PR fixes this problem as well:
note: I'm not using
console.logbecause whenstdoutdestroyed it's no longer possible to print messagesmcollina commentedon Mar 15, 2019
Here is a fix for this specific issue: #26691.
The problem was caused by
net.Sockethaving setemitClose: falsebecause it was emitted its own event in_destroy(), andstdio.jswas overriding_destroywithout emitting'close'. That PR fixes that.process: make stdout and stderr emit 'close' on destroy
process: make stdout and stderr emit 'close' on destroy
craigphicks commentedon Sep 25, 2019
Doesn't seem to be fixed using the following versions:
npm outdatedreturns nothing.As a workaround I used this:
The
_finalnot necessary, it is only there to see if it got called. It seems that_finaldoesn't get called. Unsure whether that is meaningful or not.Is it just a matter of delay between fix and stable version?
mcollina commentedon Sep 26, 2019
I think it's a separate bug, because the script at the top reports the error on both 10.16.3 and 12.11, but it does not on 10.16.0.
Can you open a new issue with a full script to reproduce?
mcollina commentedon Sep 26, 2019
I think it's a separate bug, because the script at the top reports the error on both 10.16.3 and 12.11, but it does not on 10.16.0.
Can you open a new issue with a full script to reproduce?
craigphicks commentedon Nov 5, 2019
On the other hand, maybe the default of trying to close the last stream is OK, and for those specials cases (like stdout) where its not desirable, the workaround is pretty simple.
mcollina commentedon Nov 5, 2019
I do not think I can help without a full repro of the problem you are experiencing. Can you open a new issue with a way to reproduce and tag me? Thanks
process: make stdout and stderr emit 'close' on destroy