Skip to content
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

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

ktfth
Copy link

@ktfth ktfth commented Jul 26, 2021

Included some tests to pipeline error with createTransformStream

@aduh95 aduh95 added stream Issues and PRs related to the stream subsystem. test Issues and PRs related to the tests. labels Jul 26, 2021
@aduh95
Copy link
Contributor

aduh95 commented Jul 26, 2021

/cc @nodejs/streams

@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Jul 27, 2021
@ronag
Copy link
Member

ronag commented Jul 27, 2021

Is this supposed to be a failing test? Also you probably need to spawn a child process for testing stdout.

@mcollina
Copy link
Member

cc @nodejs/streams

test/parallel/test-stream-pipeline.js Outdated Show resolved Hide resolved
@ktfth
Copy link
Author

ktfth commented Jul 27, 2021

Is this supposed to be a failing test? Also you probably need to spawn a child process for testing stdout.

Do you have an example to do that task?

@ktfth
Copy link
Author

ktfth commented Jul 27, 2021

I mading some tests before write a fix for the case

@ktfth
Copy link
Author

ktfth commented Jul 28, 2021

I'm trying do understand how the reference occur with ret and when to apply without a variable

@ktfth
Copy link
Author

ktfth commented Jul 28, 2021

@ronag and @mcollina something strange appear, the test do not fail for a case who i have created. Have some suggestions for that case in specific?

@ktfth
Copy link
Author

ktfth commented Jul 29, 2021

I working on an improvement of this solution

Copy link

@gjunkie gjunkie left a 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 Show resolved Hide resolved
try {
destroys.shift()(error);
} catch {
// Untreated destroys error
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would happen here?

Copy link
Author

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

lib/internal/streams/pipeline.js Outdated Show resolved Hide resolved
Copy link
Member

@ronag ronag left a 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?

@rluvaton
Copy link
Member

I think you should add in your tests a comment with a reference for the issue your trying to reproduce, like in:

// https://github.com/nodejs/node/issues/1068

@rluvaton
Copy link
Member

Also, as I wrote here, the issue persist with async iterators...

@ktfth
Copy link
Author

ktfth commented Jul 30, 2021

This looks wrong to me. What are we trying to solve? Does the transform stream test fail?

For me too, we are trying to solve this: #39447
Resumed the callback is not called because of destroyer, i'm looking for a new solution for that.

The test not fail on this case.

@ronag
Copy link
Member

ronag commented Jul 30, 2021

But this seems more like a problem with stdout than pipeline? Is the problem reproducible without stdout?

@ktfth
Copy link
Author

ktfth commented Jul 30, 2021

But this seems more like a problem with stdout than pipeline? Is the problem reproducible without stdout?

Yes can be reproducible without process.stdout

@ktfth
Copy link
Author

ktfth commented Jul 30, 2021

Also, as I wrote here, the issue persist with async iterators...

Working on that case

@ronag
Copy link
Member

ronag commented Jul 31, 2021

But this seems more like a problem with stdout than pipeline? Is the problem reproducible without stdout?

Yes can be reproducible without process.stdout

Do you have an example?

@ktfth
Copy link
Author

ktfth commented Jul 31, 2021

But this seems more like a problem with stdout than pipeline? Is the problem reproducible without stdout?

Yes can be reproducible without process.stdout

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?

@ronag
Copy link
Member

ronag commented Jul 31, 2021

'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');

That works fine on Node v16.3.0? What version does it fail on?

@ktfth
Copy link
Author

ktfth commented Jul 31, 2021

'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');

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

const hasNotFlush =
s._flush === undefined;
return (
hasTransform.length === 0 &&
Copy link
Member

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... 😬

@ronag
Copy link
Member

ronag commented Jul 31, 2021

With this example work fine on both versions mentioned here and on the issue. #39447

Yes? So what are we trying to solve here? Isn't it stdout?

@ktfth
Copy link
Author

ktfth commented Jul 31, 2021

With this example work fine on both versions mentioned here and on the issue. #39447

Yes? So what are we trying to solve here? Isn't it stdout?

Makes sense, can you help understand better the problem with stdout because we have something to count here but is totally a draft of a real better solution. And thank you for your time, you it is a strong connection

@ktfth
Copy link
Author

ktfth commented Jul 31, 2021

With this example work fine on both versions mentioned here and on the issue. #39447

Yes? So what are we trying to solve here? Isn't it stdout?

On the refactor i have founded some indications to process on destroyer the correctly behavior, looks good to me but need some review

ktfth added 18 commits August 4, 2021 13:29
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
@ktfth ktfth force-pushed the fix/stream-pipeline-error-callback branch from d68ccdf to dff2abb Compare August 4, 2021 16:30
Using just one solution of process.stdout
@ktfth
Copy link
Author

ktfth commented Aug 4, 2021

@ronag and @mcollina updates to something we can discuss and get into a solution

Error need to appear on callback function

Fix: nodejs#39447
@ktfth
Copy link
Author

ktfth commented Aug 5, 2021

@ronag and @mcollina I added the solution for the issue, but is just to show where this appear. Can both of you guide me for the correctly solution based on this evidence?

@ktfth
Copy link
Author

ktfth commented Aug 5, 2021

@mcollina
Copy link
Member

mcollina commented Aug 5, 2021

Is https://github.com/nodejs/node/pull/39533/files#diff-f9aa56489c061a70f83b602c8a32200b4f092a23b6eb8769f978ac1adb322a46R342 still needed?

Yes, because of the callback behavior

I removed it and it seems all tests are passing.

@ktfth
Copy link
Author

ktfth commented Aug 5, 2021

Is https://github.com/nodejs/node/pull/39533/files#diff-f9aa56489c061a70f83b602c8a32200b4f092a23b6eb8769f978ac1adb322a46R342 still needed?

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?

@ktfth
Copy link
Author

ktfth commented Aug 5, 2021

I'm not founded an example

@mcollina
Copy link
Member

mcollina commented Aug 5, 2021

Please look at #39447 (comment). On a closer look this does not seem a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ci PRs that need a full CI run. stream Issues and PRs related to the stream subsystem. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants