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

custom _destroy can swallow error? #30979

Closed
ronag opened this issue Dec 15, 2019 · 6 comments
Closed

custom _destroy can swallow error? #30979

ronag opened this issue Dec 15, 2019 · 6 comments
Labels
stream Issues and PRs related to the stream subsystem.

Comments

@ronag
Copy link
Member

ronag commented Dec 15, 2019

Was looking through the stream destroy tests and noticed this. Is this something we want? I would expect that the error would not get swallowed? i.e. I would expect the original/first error to always propagate.

  const write = new Writable({
    write(chunk, enc, cb) { cb(); },
    destroy: common.mustCall(function(err, cb) {
      assert.strictEqual(err, expected);
      cb();
    })
  });

  const expected = new Error('kaboom');

  write.on('finish', common.mustNotCall('no finish event'));
  write.on('close', common.mustCall());

  // Error is swallowed by the custom _destroy
  write.on('error', common.mustNotCall('no error event'));

  write.destroy(expected);
  assert.strictEqual(write.destroyed, true);
@ronag
Copy link
Member Author

ronag commented Dec 15, 2019

ping @lpinca

@lpinca lpinca added the stream Issues and PRs related to the stream subsystem. label Dec 15, 2019
@lpinca
Copy link
Member

lpinca commented Dec 15, 2019

It is done on purpose so I think it's ok.

@ronag
Copy link
Member Author

ronag commented Dec 15, 2019

@lpinca: then how about the case when destroy(err) is called again? Then it won't be swallowed which is a bit confusing if we are supposed to be able to suppress errors but it only works sometimes.

  const write = new Writable({
    write(chunk, enc, cb) { cb(); },
    destroy: common.mustCall(function(err, cb) {
      assert.strictEqual(err, expected);
      cb();
    })
  });

  const expected = new Error('kaboom');

  write.on('finish', common.mustNotCall('no finish event'));
  write.on('close', common.mustCall());

  // Error is swallowed by the custom _destroy
  write.on('error', common.mustNotCall('no error event'));

  write.destroy(expected);
  write.destroy(expected); // No longer swallowed... **HERE**
  assert.strictEqual(write.destroyed, true);

@lpinca
Copy link
Member

lpinca commented Dec 15, 2019

Agreed, not sure how to fix that.

@ronag
Copy link
Member Author

ronag commented Dec 15, 2019

Keep it simple and don’t allow suppressing errors? Or is that too significant?

@lpinca
Copy link
Member

lpinca commented Dec 15, 2019

I would be ok with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

No branches or pull requests

2 participants