-
-
Couldn't load subscription status.
- Fork 33.6k
lib,src: eagerly exit process on unhanded promise rejections #12734
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -168,6 +168,11 @@ void AppendExceptionLine(Environment* env, | |
| v8::Local<v8::Message> message, | ||
| enum ErrorHandlingMode mode); | ||
|
|
||
| void InternalFatalException(v8::Isolate* isolate, | ||
| v8::Local<v8::Value> error, | ||
| v8::Local<v8::Message> message, | ||
| bool from_promise); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn’t used outside of node.cc, right? |
||
|
|
||
| NO_RETURN void FatalError(const char* location, const char* message); | ||
|
|
||
| void ProcessEmitWarning(Environment* env, const char* fmt, ...); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| 'use strict'; | ||
| const common = require('../common'); | ||
|
|
||
| const p1 = new Promise((res, rej) => { | ||
| consol.log('One'); // eslint-disable-line no-undef | ||
| }); | ||
|
|
||
| const p2 = new Promise((res, rej) => { // eslint-disable-line no-unused-vars | ||
| consol.log('Two'); // eslint-disable-line no-undef | ||
| }); | ||
|
|
||
| const p3 = new Promise((res, rej) => { | ||
| consol.log('Three'); // eslint-disable-line no-undef | ||
| }); | ||
|
|
||
| new Promise((res, rej) => { | ||
| setTimeout(common.mustCall(() => { | ||
| p1.catch(() => {}); | ||
| p3.catch(() => {}); | ||
| }), 1); | ||
| }); | ||
|
|
||
| process.on('uncaughtException', (err) => | ||
| common.fail('Should not trigger uncaught exception')); | ||
|
|
||
| process.on('exit', () => process._rawDebug('exit event emitted')); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| exit event emitted | ||
| *test*message*promise_fast_handled_reject.js:* | ||
| consol.log('One'); // eslint-disable-line no-undef | ||
| ^ | ||
|
|
||
| ReferenceError: consol is not defined | ||
| at Promise (*test*message*promise_fast_handled_reject.js:*:*) | ||
| at Promise (<anonymous>) | ||
| at Object.<anonymous> (*test*message*promise_fast_handled_reject.js:*:*) | ||
| at Module._compile (module.js:*:*) | ||
| at Object.Module._extensions..js (module.js:*:*) | ||
| at Module.load (module.js:*:*) | ||
| at tryModuleLoad (module.js:*:*) | ||
| at Function.Module._load (module.js:*:*) | ||
| at Function.Module.runMain (module.js:*:*) | ||
| at startup (bootstrap_node.js:*:*) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| 'use strict'; | ||
|
|
||
| // We should always have the stacktrace of the oldest rejection. | ||
|
|
||
| const common = require('../common'); | ||
|
|
||
| new Promise(function(res, rej) { | ||
| consol.log('One'); // eslint-disable-line no-undef | ||
| }); | ||
|
|
||
| new Promise(function(res, rej) { | ||
| consol.log('Two'); // eslint-disable-line no-undef | ||
| }); | ||
|
|
||
| process.on('uncaughtException', (err) => | ||
| common.fail('Should not trigger uncaught exception')); | ||
|
|
||
| process.on('exit', () => process._rawDebug('exit event emitted')); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| exit event emitted | ||
| *test*message*promise_fast_reject.js:* | ||
| consol.log('One'); // eslint-disable-line no-undef | ||
| ^ | ||
|
|
||
| ReferenceError: consol is not defined | ||
| at *test*message*promise_fast_reject.js:*:* | ||
| at Promise (<anonymous>) | ||
| at Object.<anonymous> (*test*message*promise_fast_reject.js:*:*) | ||
| at Module._compile (module.js:*:*) | ||
| at Object.Module._extensions..js (module.js:*:*) | ||
| at Module.load (module.js:*:*) | ||
| at tryModuleLoad (module.js:*:*) | ||
| at Function.Module._load (module.js:*:*) | ||
| at Function.Module.runMain (module.js:*:*) | ||
| at startup (bootstrap_node.js:*:*) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| 'use strict'; | ||
| const common = require('../common'); | ||
|
|
||
|
|
||
| Promise.reject(new Error('oops')); | ||
|
|
||
| setImmediate(() => { | ||
| common.fail('Should not reach Immediate'); | ||
| }); | ||
|
|
||
| process.on('beforeExit', () => | ||
| common.fail('beforeExit should not be reached')); | ||
|
|
||
| process.on('uncaughtException', (err) => { | ||
| common.fail('Should not trigger uncaught exception'); | ||
| }); | ||
|
|
||
| process.on('exit', () => process._rawDebug('exit event emitted')); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| exit event emitted | ||
| *test*message*promise_reject.js:* | ||
| Promise.reject(new Error('oops')); | ||
| ^ | ||
|
|
||
| Error: oops | ||
| at *test*message*promise_reject.js:*:* | ||
| at Module._compile (module.js:*:*) | ||
| at Object.Module._extensions..js (module.js:*:*) | ||
| at Module.load (module.js:*:*) | ||
| at tryModuleLoad (module.js:*:*) | ||
| at Function.Module._load (module.js:*:*) | ||
| at Function.Module.runMain (module.js:*:*) | ||
| at startup (bootstrap_node.js:*:*) | ||
| at bootstrap_node.js:*:* |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| 'use strict'; | ||
| const common = require('../common'); | ||
|
|
||
| // Flags: --expose-gc | ||
|
|
||
| const p = new Promise((res, rej) => { | ||
| consol.log('oops'); // eslint-disable-line no-undef | ||
| }); | ||
|
|
||
| // Manually call GC due to possible memory contraints with attempting to | ||
| // trigger it "naturally". | ||
| process.nextTick(common.mustCall(() => { | ||
| p.catch(() => {}); | ||
| /* eslint-disable no-undef */ | ||
| gc(); | ||
| gc(); | ||
| gc(); | ||
| /* eslint-enable no-undef */ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as in the other PR(s?): Do you need the linter comments if you use |
||
| }, 1)); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| 'use strict'; | ||
| require('../common'); | ||
| const common = require('../common'); | ||
| const assert = require('assert'); | ||
| const domain = require('domain'); | ||
|
|
||
|
|
@@ -673,6 +673,8 @@ asyncTest('Throwing an error inside a rejectionHandled handler goes to' + | |
| tearDownException(); | ||
| done(); | ||
| }); | ||
| // Prevent fatal unhandled error. | ||
| process.on('unhandledRejection', common.noop); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: |
||
| process.on('rejectionHandled', function() { | ||
| throw e2; | ||
| }); | ||
|
|
||
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.
tiny nit: CHECK_EQ? :)