Skip to content

stream: avoid unhandled exception when destroy w/ callback.#30970

Closed
ronag wants to merge 1 commit into
nodejs:masterfrom
nxtedition:stream-destroy-error-cb
Closed

stream: avoid unhandled exception when destroy w/ callback.#30970
ronag wants to merge 1 commit into
nodejs:masterfrom
nxtedition:stream-destroy-error-cb

Conversation

@ronag

@ronag ronag commented Dec 14, 2019

Copy link
Copy Markdown
Member

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
Comment thread lib/internal/streams/destroy.js Outdated
Comment thread lib/internal/streams/destroy.js Outdated

Copy link
Copy Markdown
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'?

@ronag ronag Dec 15, 2019

Copy link
Copy Markdown
Member Author

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

ronag commented Dec 15, 2019

Copy link
Copy Markdown
Member Author

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

@lpinca

lpinca commented Dec 15, 2019

Copy link
Copy Markdown
Member

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

lpinca commented Dec 15, 2019

Copy link
Copy Markdown
Member

@nodejs/streams

@ronag

ronag commented Dec 15, 2019

Copy link
Copy Markdown
Member Author

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
ronag force-pushed the stream-destroy-error-cb branch from 1755b8c to 248c405 Compare December 15, 2019 10:15
@ronag

ronag commented Dec 15, 2019

Copy link
Copy Markdown
Member Author

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.

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

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

ronag commented Dec 15, 2019

Copy link
Copy Markdown
Member Author

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

@BridgeAR BridgeAR left a comment

Copy link
Copy Markdown
Member

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

ronag commented Dec 26, 2019

Copy link
Copy Markdown
Member Author

Blocked by #29179

@ronag

ronag commented Dec 26, 2019

Copy link
Copy Markdown
Member Author

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