GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — domains: fix handling of uncaught exceptions by misterdjules · Pull Request #3654 · nodejs/node

Conversation

@misterdjules

@misterdjules misterdjules commented Nov 4, 2015

Copy link
Copy Markdown

Fix node exiting due to an exception being thrown rather than emitting
an 'uncaughtException' event on the process object when:

  1. no error handler is set on the domain within which an error is thrown
  2. an 'uncaughtException' event listener is set on the process

Also fix an issue where the process would not abort in the proper
function call if an error is thrown within a domain with no error
handler and --abort-on-uncaught-exception is used.

Finally, change the behavior of --abort-on-uncaught-exception so that,
if the domain within which the error is thrown has no error handler, but
a domain further up the domains stack has one, the process will not
abort.

Fixes #3607 and #3653.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@misterdjules misterdjules added the domain Issues and PRs related to the domain subsystem. label Nov 4, 2015
@misterdjules

misterdjules commented Nov 4, 2015

Copy link
Copy Markdown
Author

This PR is based on top of #3640. We might want to consolidate both PRs into one, but since this one adds a commit with more substantial changes, I thought I would submit it separately.

Landing #3640 and not this PR creates the problem where the following code:

const domain = require('domain');
d.run(function() { throw new Error('boom'); });

would not make node abort when using --abort-on-uncaught-exception.

So depending on how urgent it is to fix #3607 which #3640 fixes, and how long it would take to review the second commit in this PR, we could either land both commits at once into one commit, or land #3640 first and then this PR.

Once the review for this PR targeted to master is done, I will back port it to the v0.10 and v0.12 branches.

/cc @nodejs/tsc @nodejs/lts @nodejs/collaborators

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@misterdjules misterdjules added the lts-watch-v4.x label Nov 4, 2015
thefourtheye
thefourtheye reviewed Nov 4, 2015
View reviewed changes
Comment thread lib/domain.js

@thefourtheye thefourtheye Nov 4, 2015

Copy link
Copy Markdown
Contributor

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.

We use camel case, right?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@misterdjules misterdjules Nov 4, 2015

Copy link
Copy Markdown
Author

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.

Generally, yes, although it seems it's not enforced by the linter. Are you saying that I should fix _domain_flag's name to be camel cased? This is not an addition from this PR, so i'd rather focus on the changes that this PR makes and fix that later.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jasnell jasnell Nov 5, 2015

Copy link
Copy Markdown
Member

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.

I agree with @misterdjules

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@misterdjules misterdjules mentioned this pull request Nov 4, 2015
Domains inhibit uncaughtException error handling #3607
Closed
trevnorris
trevnorris reviewed Nov 4, 2015
View reviewed changes
Comment thread src/node.cc Outdated

@trevnorris trevnorris Nov 4, 2015

Copy link
Copy Markdown
Contributor

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.

style nit: these cases should be indented 4 spaces. the linter not catching this?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@misterdjules misterdjules Nov 23, 2015

Copy link
Copy Markdown
Author

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.

@trevnorris It seems the linter is not catching this, but I've updated the PR as suggested. Thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@misterdjules
misterdjules force-pushed the fix-abort-on-uncaught-domain-error-handlers branch from 00eea60 to 8c835d2 Compare November 4, 2015 20:34
@misterdjules misterdjules mentioned this pull request Nov 4, 2015
domains: emit uncaughtException when appropriate #3640
Closed
@misterdjules
misterdjules force-pushed the fix-abort-on-uncaught-domain-error-handlers branch from 8c835d2 to c850253 Compare November 4, 2015 20:48
@jasnell

jasnell commented Nov 5, 2015

Copy link
Copy Markdown
Member

hmm... the change looks good but given that this changes the error handling, this would need to be semver-minor or semver-major wouldn't it? @nodejs/ctc

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@misterdjules

misterdjules commented Nov 6, 2015

Copy link
Copy Markdown
Author

@jasnell The issue that the first commit in this PR fixes is a regression from node v4.1.2. That is, #3607 cannot be reproduced with node v4.1.2, but can be reproduced since node v4.2.0.

The first commit in this PR fixes that issue, but it also exposed a bug in the way we handle uncaught exceptions within domains when --abort-on-uncaught-exception is used on the command line. The second commit fixes that bug.

The change in behavior is in the following situation:

var domain = require('domain');
var d1 = domain.create();
var d2 = domain.create();

d1.on('error', function() {
});

d1.run(function() {
  d2.run(function() {
    throw new Error('boom');
  }
}

Previously, when using --abort-on-uncaught-exception, this code would abort. Now, it doesn't because we consider that the domain d1 can handle the error.

Note that in the case of an async operation's callback throwing the error:

var domain = require('domain');
var d1 = domain.create();
var d2 = domain.create();

d1.on('error', function() {
});

d1.run(function() {
  d2.run(function() {
    setImmediate(function() {
      throw new Error('boom');
    });
  }
}

running this code with --abort-on-uncaught-exception still aborts because the domains stack at the time the setImmediate callback is called only contains the domain d2, which doesn't have any error handler set.

I agree that this specific behavior change could be a breaking change, but this PR can be easily changed to not change this behavior and still fix the rest of the issues it fixes.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented Nov 6, 2015

Copy link
Copy Markdown
Member

hmm ok. we may need to do split it up that way then... which I know is a pain but we need to be very careful about potentially breaking changes landing in LTS.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@misterdjules

misterdjules commented Nov 6, 2015

Copy link
Copy Markdown
Author

@jasnell No worries and thank you for discussing how to come up with a good solution, I don't consider it as being a pain.

Is:

  1. Submitting a PR targeted to v5.x without this behavior change
  2. Cherry-picking the commit in v4.x when it lands in v5.x
  3. Keeping this PR on master so that it can actually land on master with the behavior change (to eventually be in v6.x)

the right way to move forward?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented Nov 13, 2015

Copy link
Copy Markdown
Member

Sorry @misterdjules ... just now saw your response on this one. We might be able to get away with being more lenient on landing the behavior change in v5.x. I would say land in master, cherry pick to v5.x, then cherry pick a subset (without the behavior change) to v4.x. Then, in the next v4.x release, we can document the issue in the known issues and indicate that it's been fixed fully in v5.x and master.

@rvagg @Fishrock123 ... does that seem reasonable?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@misterdjules

misterdjules commented Nov 13, 2015

Copy link
Copy Markdown
Author

@jasnell OK, so I will:

  • Submit a new PR targeted to v4.x-staging without the behavior change.
  • Update the PRs on v0.12 and v0.10 to not contain the behavior change.
  • Keep the PR as it is on master (except for squashing the two commits into one).

Then I'll tag that PR on master as "land-on-v5.x" (whatever the proper spelling for that tag is), and we can decide how we want to land it there. I personally don't see any need to land it with the behavior change on v5.x, as long as it lands with the behavior change on master.

The goal being that eventually the behavior of domains used with --abort-on-uncaught-exception is more consistent with when --abort-on-uncaught-exception is not used, but it doesn't need to happen in v5.x.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented Nov 13, 2015

Copy link
Copy Markdown
Member

+1

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jamestalmage jamestalmage mentioned this pull request Nov 14, 2015
Use domains to track which test threw an error. avajs/ava#214
Closed
@misterdjules
misterdjules force-pushed the fix-abort-on-uncaught-domain-error-handlers branch from c850253 to b1deae5 Compare November 17, 2015 18:24
@misterdjules

misterdjules commented Nov 17, 2015

Copy link
Copy Markdown
Author

@jasnell @nodejs/ctc @nodejs/collaborators Squashed into one commit, updated commit message and original description of the PR. Please take a look.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bnoordhuis
bnoordhuis reviewed Nov 17, 2015
View reviewed changes
Comment thread lib/domain.js Outdated

@bnoordhuis bnoordhuis Nov 17, 2015

Copy link
Copy Markdown
Member

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.

Can you use const and properly capitalize the comment while you're here?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@misterdjules misterdjules Nov 19, 2015

Copy link
Copy Markdown
Author

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.

Will fix!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@misterdjules

misterdjules commented Dec 3, 2015

Copy link
Copy Markdown
Author

@DonutEspresso Going through the comments I actually found a few typos that I will fix shortly. Thank you, very much appreciated!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@chrisdickinson

chrisdickinson commented Dec 3, 2015

Copy link
Copy Markdown
Contributor

With the current state of this PR, it would be caught by the tests suite: at least one test would fail if EventEmitter.prototype._events was changed in a way that breaks uncaught exceptions handling. I have the feeling this is enough, and that we would probably need to add a lot of similar comments elsewhere if we add one there. But I don't have a strong opinion, so if you'd still like me to add a comment I'll be happy to do so!

That's totally fair! If the tests break then that should be a good enough signal to go on :)

Other than the missing test case, LGTM!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@misterdjules

misterdjules commented Dec 11, 2015

Copy link
Copy Markdown
Author

@chrisdickinson Added a second commit that adds a test in test/parallel/test-domain-throw-error-then-throw-from-uncaught-exception-handler.js. Since it needs to check if a node process actually aborts in one case, and this also needs to be done in other tests, I factored that logic in a new nodeProcessAborted function defined in test/common.js.

A third commit also fixes some typos in the tests' comments.

Can you please take a look, and if these changes look good to you, I'll squash all commits in this PR into one commit.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@chrisdickinson

chrisdickinson commented Dec 11, 2015

Copy link
Copy Markdown
Contributor

LGTM!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@misterdjules
misterdjules force-pushed the fix-abort-on-uncaught-domain-error-handlers branch from 375d3a8 to 28ef2a1 Compare December 11, 2015 07:17
@misterdjules

misterdjules commented Dec 11, 2015

Copy link
Copy Markdown
Author

@chrisdickinson I've actually changed test/parallel/test-domain-throw-error-then-throw-from-uncaught-exception-handler.js a bit to avoid creating core files, which is what's done in any other similar test.

I took that opportunity to check that the error messages on stderr were consistent with what's expected. It doesn't change the nature/implementation of the test too much though, so I'll consider your LGTM still stands and land that once CI tests results are OK.

Thank you once again!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@misterdjules

misterdjules commented Dec 11, 2015

Copy link
Copy Markdown
Author

Tagging as semver-minor as per a previous discussion that happened a while ago in this PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@misterdjules misterdjules added the semver-minor PRs that contain new features and should be released in the next minor version. label Dec 11, 2015
@misterdjules

misterdjules commented Dec 11, 2015

Copy link
Copy Markdown
Author

Previous CI tests results had a failure on Windows in test/parallel/test-domain-throw-error-then-throw-from-uncaught-exception-handler.js. I pushed an additional commit that fixes the issue, and restarted CI tests.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Julien Gilli
domains: fix handling of uncaught exceptions
c76959a
Fix node exiting due to an exception being thrown rather than emitting
an `'uncaughtException'` event on the process object when:
1. no error handler is set on the domain within which an error is thrown
2. an `'uncaughtException'` event listener is set on the process

Also fix an issue where the process would not abort in the proper
function call if an error is thrown within a domain with no error
handler and `--abort-on-uncaught-exception` is used.

Finally, change the behavior of --abort-on-uncaught-exception so that,
if the domain within which the error is thrown has no error handler, but
a domain further up the domains stack has one, the process will not
abort.

Fixes nodejs#3607 and nodejs#3653.
@misterdjules
misterdjules force-pushed the fix-abort-on-uncaught-domain-error-handlers branch from 46f36ac to c76959a Compare December 11, 2015 22:31
@misterdjules

misterdjules commented Dec 11, 2015

Copy link
Copy Markdown
Author

@nodejs/ctc CI tests all passed, except for existing flaky tests. Will land asap.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

misterdjules pushed a commit that referenced this pull request Dec 11, 2015
Julien Gilli
domains: fix handling of uncaught exceptions
425a354
Fix node exiting due to an exception being thrown rather than emitting
an `'uncaughtException'` event on the process object when:
1. no error handler is set on the domain within which an error is thrown
2. an `'uncaughtException'` event listener is set on the process

Also fix an issue where the process would not abort in the proper
function call if an error is thrown within a domain with no error
handler and `--abort-on-uncaught-exception` is used.

Finally, change the behavior of --abort-on-uncaught-exception so that,
if the domain within which the error is thrown has no error handler, but
a domain further up the domains stack has one, the process will not
abort.

Fixes #3607 and #3653.

PR: #3654
PR-URL: #3654
Reviewed-By: Chris Dickinson <[email protected]>
@misterdjules

misterdjules commented Dec 11, 2015

Copy link
Copy Markdown
Author

Landed in 425a354.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@misterdjules misterdjules closed this Dec 11, 2015
@Fishrock123 Fishrock123 mentioned this pull request Dec 15, 2015
v5.3.0 Release Proposal (Stable) #4281
Closed
misterdjules pushed a commit that referenced this pull request Dec 15, 2015
Julien Gilli @cjihrig
domains: fix handling of uncaught exceptions
e8a6b65
Fix node exiting due to an exception being thrown rather than emitting
an `'uncaughtException'` event on the process object when:
1. no error handler is set on the domain within which an error is thrown
2. an `'uncaughtException'` event listener is set on the process

Also fix an issue where the process would not abort in the proper
function call if an error is thrown within a domain with no error
handler and `--abort-on-uncaught-exception` is used.

Finally, change the behavior of --abort-on-uncaught-exception so that,
if the domain within which the error is thrown has no error handler, but
a domain further up the domains stack has one, the process will not
abort.

Fixes #3607 and #3653.

PR: #3654
PR-URL: #3654
Reviewed-By: Chris Dickinson <[email protected]>
cjihrig added a commit that referenced this pull request Dec 15, 2015
@cjihrig
2015-12-15, Version 5.3.0 (Stable)
ea5f3ab
Notable changes:

* domains:
  - Fix handling of uncaught exceptions.
    (Julien Gilli) #3654.
* https:
  - Added support for disabling session caching.
    (Fedor Indutny) #4252.
* repl:
  - Allow third party modules to be imported using
    require(). This corrects a regression from 5.2.0.
    (Ben Noordhuis) #4215.
* deps:
  - Upgrade libuv to 1.8.0.
    (Saúl Ibarra Corretgé) #4276.

PR-URL: #4281
cjihrig added a commit that referenced this pull request Dec 16, 2015
@cjihrig
2015-12-16, Version 5.3.0 (Stable)
b21110f
Notable changes:

* buffer:
  - Buffer.prototype.includes() has been added to keep parity
    with TypedArrays. (Alexander Martin) #3567.
* domains:
  - Fix handling of uncaught exceptions.
    (Julien Gilli) #3654.
* https:
  - Added support for disabling session caching.
    (Fedor Indutny) #4252.
* repl:
  - Allow third party modules to be imported using
    require(). This corrects a regression from 5.2.0.
    (Ben Noordhuis) #4215.
* deps:
  - Upgrade libuv to 1.8.0.
    (Saúl Ibarra Corretgé) #4276.

PR-URL: #4281
cjihrig added a commit that referenced this pull request Dec 16, 2015
@cjihrig
2015-12-16, Version 5.3.0 (Stable)
e5774c9
Notable changes:

* buffer:
  - Buffer.prototype.includes() has been added to keep parity
    with TypedArrays. (Alexander Martin) #3567.
* domains:
  - Fix handling of uncaught exceptions.
    (Julien Gilli) #3654.
* https:
  - Added support for disabling session caching.
    (Fedor Indutny) #4252.
* repl:
  - Allow third party modules to be imported using
    require(). This corrects a regression from 5.2.0.
    (Ben Noordhuis) #4215.
* deps:
  - Upgrade libuv to 1.8.0.
    (Saúl Ibarra Corretgé) #4276.

PR-URL: #4281

Conflicts:
	src/node_version.h
@saper

saper commented Jan 6, 2016

Copy link
Copy Markdown

Everyone: do you think sass/node-sass#1283 is instance of this bug?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@misterdjules

misterdjules commented Jan 6, 2016

Copy link
Copy Markdown
Author

@saper Do you mean:

  1. Was Exit status 3221225477 returned from node scripts/build.js / Windows XP sass/node-sass#1283 fixed by this PR?
  2. Was Exit status 3221225477 returned from node scripts/build.js / Windows XP sass/node-sass#1283 introduced by this PR?

I don't see how it could be 1), but it could be 2), although it seems unlikely. Ideally we would have a callstack at the time the process aborted. But that's a discussion that should happen in sass/node-sass#1283 first.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@saper

saper commented Jan 6, 2016

Copy link
Copy Markdown

I haven't checked yet which versions of node this patch is in, so I don't know whether it's 1 or 2. We started getting those reports only very recently (and it seems we have great deal of Windows XP users #3604 ). I will try to reproduce that myself on the XP box.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@saper saper mentioned this pull request Jan 6, 2016
Exit status 3221225477 returned from node scripts/build.js / Windows XP sass/node-sass#1283
Closed
@saper

saper commented Jan 6, 2016

Copy link
Copy Markdown

Sorry for noise, it looks like it is a regression in our code.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

scovetta pushed a commit to scovetta/node that referenced this pull request Apr 2, 2016
Julien Gilli Michael Scovetta
domains: fix handling of uncaught exceptions
3a5eb84
Fix node exiting due to an exception being thrown rather than emitting
an `'uncaughtException'` event on the process object when:
1. no error handler is set on the domain within which an error is thrown
2. an `'uncaughtException'` event listener is set on the process

Also fix an issue where the process would not abort in the proper
function call if an error is thrown within a domain with no error
handler and `--abort-on-uncaught-exception` is used.

Finally, change the behavior of --abort-on-uncaught-exception so that,
if the domain within which the error is thrown has no error handler, but
a domain further up the domains stack has one, the process will not
abort.

Fixes nodejs#3607 and nodejs#3653.

PR: nodejs#3654
PR-URL: nodejs#3654
Reviewed-By: Chris Dickinson <[email protected]>
scovetta pushed a commit to scovetta/node that referenced this pull request Apr 2, 2016
@cjihrig Michael Scovetta
2015-12-16, Version 5.3.0 (Stable)
c74c53a
Notable changes:

* buffer:
  - Buffer.prototype.includes() has been added to keep parity
    with TypedArrays. (Alexander Martin) nodejs#3567.
* domains:
  - Fix handling of uncaught exceptions.
    (Julien Gilli) nodejs#3654.
* https:
  - Added support for disabling session caching.
    (Fedor Indutny) nodejs#4252.
* repl:
  - Allow third party modules to be imported using
    require(). This corrects a regression from 5.2.0.
    (Ben Noordhuis) nodejs#4215.
* deps:
  - Upgrade libuv to 1.8.0.
    (Saúl Ibarra Corretgé) nodejs#4276.

PR-URL: nodejs#4281

Conflicts:
	src/node_version.h
@rnchamberlain rnchamberlain mentioned this pull request Mar 15, 2017
illegal hardware exception nodejs/node-report#6
Closed
@misterdjules
misterdjules deleted the fix-abort-on-uncaught-domain-error-handlers branch July 24, 2017 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

domain Issues and PRs related to the domain subsystem. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Domains inhibit uncaughtException error handling

Uh oh!

There was an error while loading. Please reload this page.

10 participants

@misterdjules @jasnell @bnoordhuis @rvagg @chrisdickinson @yunong @DonutEspresso @saper @trevnorris @thefourtheye
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.