-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stream.pipeline does not invoke callback when error happens #39447
Comments
@nodejs/streams |
The problem is that '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? |
Oh, makes sense. Thanks @mcollina for clarifying this issue for me. |
@mcollina I have some questions... |
I'm made some progress investigating the code base, but if it's possible to talk more about that could be helpful. |
The pipeline should call the last function as error handler on that part a test was created related to a discussion on project. Refs: nodejs#39447
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. |
The test consist on usage of process.stdout in pipeline returning an error when done Refs: nodejs#39447
Included 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? |
I can do that |
The pipeline should call the last function as error handler on that part a test was created related to a discussion on project. Refs: nodejs#39447
The test consist on usage of process.stdout in pipeline returning an error when done Refs: nodejs#39447
PR: #39533 |
The fix consist in to check a specific case of pipeline Fix: nodejs#39447
I wanted to know if the problem persist when using an const { Transform, pipeline } = require('stream')
function createTransformStream () {
return async function*(stream) {
yield 'test';
throw new Error('Artificial Error');
};
}
const ts = createTransformStream()
pipeline(ts, process.stdout, (err) => {
if (err) console.log(err);
console.log('done')
})
console.log('run test') |
The pipeline should call the last function as error handler on that part a test was created related to a discussion on project. Refs: nodejs#39447
The test consist on usage of process.stdout in pipeline returning an error when done Refs: nodejs#39447
The fix consist in to check a specific case of pipeline Fix: nodejs#39447
The fix consist on check not existence for async iterator Fix: nodejs#39447
Checked the right place of error with a better solution on refactor Fix: nodejs#39447
The pipeline should call the last function as error handler on that part a test was created related to a discussion on project. Refs: nodejs#39447
The test consist on usage of process.stdout in pipeline returning an error when done Refs: nodejs#39447
The fix consist in to check a specific case of pipeline Fix: nodejs#39447
The pipeline should call the last function as error handler on that part a test was created related to a discussion on project. Refs: nodejs#39447
The test consist on usage of process.stdout in pipeline returning an error when done Refs: nodejs#39447
The fix consist in to check a specific case of pipeline Fix: nodejs#39447
Checked the right place of error with a better solution on refactor Fix: nodejs#39447
If I'm right in my assumption about the error - #39533 (comment) (in 3-4 words - the A workaround would be to just wrap the |
The pipeline should call the last function as error handler on that part a test was created related to a discussion on project. Refs: nodejs#39447
The test consist on usage of process.stdout in pipeline returning an error when done Refs: nodejs#39447
The fix consist in to check a specific case of pipeline Fix: nodejs#39447
The pipeline should call the last function as error handler on that part a test was created related to a discussion on project. Refs: nodejs#39447
The test consist on usage of process.stdout in pipeline returning an error when done Refs: nodejs#39447
The fix consist in to check a specific case of pipeline Fix: nodejs#39447
Checked the right place of error with a better solution on refactor Fix: nodejs#39447
On the domain of process.stdout we removed check and now we emit error on destroyer Fix: nodejs#39447
Error need to appear on callback function Fix: nodejs#39447
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 |
According to #7606 (comment) stdio should never be closed |
the actual file descriptor is never closed. However the stream object |
I understand and totally agree |
Closing the stdio can have an unwanted results:
I'm sure there are more reasons, this is just at the top of my head. I think we should fix the |
This change matches our bootstrap code that never closes stdout or stdeer. As the file descriptors are never closed, calling `process.stdout.destroy()` should not prevent `console.log()` for working. Fixes: nodejs#39447
Here is an alternative way to fix this: #39670 |
This change makes `process.stdout` and `process.stderr` to be automatically undestroyed when ended/destrouyed, therefore making it always possible to write/console.log to stdout. Fixes: nodejs#39447
This change makes `process.stdout` and `process.stderr` to be automatically undestroyed when ended/destrouyed, therefore making it always possible to write/console.log to stdout. Fixes: nodejs#39447
This change makes `process.stdout` and `process.stderr` to be automatically undestroyed when ended/destrouyed, therefore making it always possible to write/console.log to stdout. Fixes: #39447 PR-URL: #39685 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
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
pipeline
callback to be called with error argument. So I'll have the output like this:What do you see instead?
pipeline
callback is not called. Output that I have:Additional information
When I run mentioned code with
--inspect-brk
flag — I can achieve expected behaviour in google chrome console. Steps:node --inspect-brk demo.js
chrome://inspect/#devices
in chromeThe text was updated successfully, but these errors were encountered: