-
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 error callback #39533
base: main
Are you sure you want to change the base?
Conversation
/cc @nodejs/streams |
Is this supposed to be a failing test? Also you probably need to spawn a child process for testing stdout. |
cc @nodejs/streams |
Do you have an example to do that task? |
I mading some tests before write a fix for the case |
I'm trying do understand how the reference occur with ret and when to apply without a variable |
I working on an improvement of this solution |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left just a couple of small, non-blocking comments.
lib/internal/streams/pipeline.js
Outdated
try { | ||
destroys.shift()(error); | ||
} catch { | ||
// Untreated destroys error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would happen here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In some cases the shift function are not encountered
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks wrong to me. What are we trying to solve? Does the transform stream test fail?
I think you should add in your tests a comment with a reference for the issue your trying to reproduce, like in:
|
Also, as I wrote here, the issue persist with async iterators... |
For me too, we are trying to solve this: #39447 The test not fail on this case. |
But this seems more like a problem with stdout than pipeline? Is the problem reproducible without stdout? |
Yes can be reproducible without process.stdout |
Working on that case |
Do you have an example? |
'use strict';
const {
Transform,
Writable,
pipeline,
} = require('stream');
const assert = require('assert');
function createTransformStream(tf, context) {
return new Transform({
readableObjectMode: true,
writableObjectMode: true,
transform(chunk, encoding, done) {
tf(chunk, context, done);
}
});
}
const write = new Writable({
write(data, enc, cb) {
cb();
}
});
const ts = createTransformStream((chunk, _, done) => {
return done(new Error('Artificial error'));
});
pipeline(ts, write, (err) => {
assert.ok(err, 'should have an error');
console.log(err);
});
ts.write('test'); The case above help? |
That works fine on Node v16.3.0? What version does it fail on? |
With this example work fine on both versions mentioned here and on the issue. #39447 |
lib/internal/streams/pipeline.js
Outdated
const hasNotFlush = | ||
s._flush === undefined; | ||
return ( | ||
hasTransform.length === 0 && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's just me but what's the point of this? It seems very confusing to check the length of the array that you're assigning to... 😬
Yes? So what are we trying to solve here? Isn't it |
Makes sense, can you help understand better the problem with |
On the refactor i have founded some indications to process on destroyer the correctly behavior, looks good to me but need some review |
Testing a basic case of createTransformStream with pipeline for a process of pipe transformers
Output of a basic case of stream pipeline
Just doing the check for output
Callback was called when a error happen
The final function has an deviation of behavior for callback error fixed on a smallest case
The fix consist in to check a specific case of pipeline Fix: nodejs#39447
Solved the pipeline callback error, now a refactor comes
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
Complete the solve of conflicts
Testing a basic case of createTransformStream with pipeline for a process of pipe transformers
Just doing the check for output
The final function has an deviation of behavior for callback error fixed on a smallest case
The fix consist in to check a specific case of pipeline Fix: nodejs#39447
Added a check for async iterator
Some checks fixed on test of async iterator
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
d68ccdf
to
dff2abb
Compare
Using just one solution of process.stdout
Error need to appear on callback function Fix: nodejs#39447
Yes, because of the callback behavior |
I removed it and it seems all tests are passing. |
There is an issue with that, you know how force test check the callback? |
I'm not founded an example |
Please look at #39447 (comment). On a closer look this does not seem a bug. |
Included some tests to pipeline error with createTransformStream