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: avoid unhandled exception when destroy w/ callback. #30970

Closed
wants to merge 1 commit into from

Conversation

ronag
Copy link
Member

@ronag ronag commented Dec 14, 2019

Providing a callback to destroy means that the error should be handled through that callback and thus an unhandled exception error should not be necessary.

Some minor preparation towards possibly making the destroy(err, cb) signature public.

With "better" ergonomics I'm hoping users that usually skip adding an 'error' listeners before destroy() no longer end up with unhandled exceptions in edge cases.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@ronag ronag force-pushed the stream-destroy-error-cb branch 2 times, most recently from 49f20a0 to badc716 Compare December 14, 2019 23:54
@@ -52,6 +54,11 @@ function destroy(err, cb) {
r.destroyed = true;
}

if (cb) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps here and elsewhere in this function we should instead check typeof cb === 'function'?

Copy link
Member Author

@ronag ronag Dec 15, 2019

Choose a reason for hiding this comment

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

We don't do that anywhere else in this file. If you'd prefer it like that, I would prefer to handle that in a separate PR and change it everywhere in this file.

@ronag
Copy link
Member Author

ronag commented Dec 15, 2019

@lpinca: Are you ok with this change? The error is not swallowed per se.

@lpinca
Copy link
Member

lpinca commented Dec 15, 2019

Is there a particular reason? Adding 'error' events is user responsibility and it is has been a Node.js feature from the very early days. I don't think we should make it optional if a callback is passed to stream.destroy(). We add no default listener if a callback is passed to writable.write().

@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

@nodejs/streams

@ronag
Copy link
Member Author

ronag commented Dec 15, 2019

For me this is about the unhandled exception behavior

I don't think we should make it optional if a callback is passed to stream.destroy().

We emit an unhandled exception error and close the program because the exception is supposedly unhandled. If the user provides a callback and do handle it, this behavior is in my opinion both unintuitive and unnecessary.

We add no default listener if a callback is passed to writable.write().

I think that might be worth into looking into / consider updating those and others as well. I was hoping to propose that in a separate semver major PR if there is consensus on this one.

Providing a callback to destroy means that the error should be
handled through that callback and thus an unhandled exception
error should not be necessary.
@ronag
Copy link
Member Author

ronag commented Dec 15, 2019

For context I'm just probing a bit in regards to how much of normalized destroy would make sense to move into core streams and how much makes sense to be an outside util.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

We are using that callback internally at least once. Can you please verify where we are using it right now and if this would break them?

I think this is semver-major.

Docs are missing.

@ronag
Copy link
Member Author

ronag commented Dec 15, 2019

We are using that callback internally at least once. Can you please verify where we are using it right now and if this would break them?

onWriteComplete unfortunately uses it which might change the behavior more than intended. Probably safe but we might as well wait for #29179 which would fix this. So this PR is probably blocked by that.

Given the limited use we could also fix so that the cb is invoked asynchronously like the rest.

Docs are missing.

This is not a public API (yet).

Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

This needs a rebase.

@ronag
Copy link
Member Author

ronag commented Dec 26, 2019

Blocked by #29179

@ronag
Copy link
Member Author

ronag commented Dec 26, 2019

Been some related progress on other PR's. Closing this for now and re-opening later.

@ronag ronag closed this Dec 26, 2019
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

Successfully merging this pull request may close these issues.

5 participants