-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
domains: fix handling of uncaught exceptions #3654
domains: fix handling of uncaught exceptions #3654
Conversation
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:
would not make node abort when using 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 |
// let the process know we're using domains | ||
const _domain_flag = process._setupDomainUse(_domain); | ||
const _domain_flag = process._setupDomainUse(_domain, stack); |
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?
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.
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
return false; | ||
|
||
Local<Value> domain_error_listeners_v = | ||
domain_event_listeners_o->Get(env->error_string()); |
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?
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!
00eea60
to
8c835d2
Compare
8c835d2
to
c850253
Compare
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 |
@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 The change in behavior is in the following situation:
Previously, when using Note that in the case of an async operation's callback throwing the error:
running this code with 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. |
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. |
@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:
the right way to move forward? |
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 @rvagg @Fishrock123 ... does that seem reasonable? |
@jasnell OK, so I will:
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 |
+1 |
c850253
to
b1deae5
Compare
@jasnell @nodejs/ctc @nodejs/collaborators Squashed into one commit, updated commit message and original description of the PR. Please take a look. |
@@ -27,8 +27,13 @@ Object.defineProperty(process, 'domain', { | |||
} | |||
}); | |||
|
|||
// it's possible to enter one domain while already inside | |||
// another one. the stack is each entered domain. | |||
var stack = []; |
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?
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!
@DonutEspresso Going through the comments I actually found a few typos that I will fix shortly. Thank you, very much appreciated! |
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! |
@chrisdickinson Added a second commit that adds a test in 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. |
LGTM! |
375d3a8
to
28ef2a1
Compare
@chrisdickinson I've actually changed 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! |
Tagging as semver-minor as per a previous discussion that happened a while ago in this PR. |
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. |
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.
46f36ac
to
c76959a
Compare
@nodejs/ctc CI tests all passed, except for existing flaky tests. Will land asap. |
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]>
Landed in 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]>
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
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
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
Everyone: do you think sass/node-sass#1283 is instance of this bug? |
@saper Do you mean:
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. |
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. |
Sorry for noise, it looks like it is a regression in our code. |
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]>
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
Fix node exiting due to an exception being thrown rather than emitting
an
'uncaughtException'
event on the process object when:'uncaughtException'
event listener is set on the processAlso 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.