-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
process: do not directly schedule _tickCallback in _fatalException
When a process encounters a _fatalException that is caught, it should schedule execution of nextTicks but not in an arbitrary place of the next Immediates queue. Instead, add a no-op function to the queue that will ensure processImmediate runs, which will then ensure that nextTicks are processed at the end. Backport-PR-URL: #19006 PR-URL: #17841 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
1 parent
d348496
commit 4acea14
Showing
2 changed files
with
44 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
// If a process encounters an uncaughtException, it should schedule | ||
// processing of nextTicks on the next Immediates cycle but not | ||
// before all Immediates are handled | ||
|
||
let stage = 0; | ||
|
||
process.once('uncaughtException', common.expectsError({ | ||
type: Error, | ||
message: 'caughtException' | ||
})); | ||
|
||
setImmediate(() => { | ||
stage++; | ||
process.nextTick(() => assert.strictEqual(stage, 2)); | ||
}); | ||
const now = Date.now(); | ||
setTimeout(() => setImmediate(() => stage++), 1); | ||
while (now + 10 >= Date.now()); | ||
throw new Error('caughtException'); |