-
Notifications
You must be signed in to change notification settings - Fork 29.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: no call to SetIdle() when terminating
Calling SetIdle() when terminating is not harmless. When node terminates due to an unhandled exception, v8 preseves the vm state, which is JS and notifies node through PerIsolateMessageListener(). If node calls SetIdle() later, v8 complains because it requires the vm state to either be EXTERNEL or IDLE when embedder calling SetIdle().
- Loading branch information
Showing
2 changed files
with
29 additions
and
1 deletion.
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
27 changes: 27 additions & 0 deletions
27
test/parallel/test-unhandled-exception-with-worker-inuse.js
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,27 @@ | ||
'use strict'; | ||
require('../common'); | ||
|
||
// Check that node will not call v8::Isolate::SetIdle() when exiting | ||
// due to an unhandled exception, otherwise the assertion(enabled in | ||
// debug build only) in the SetIdle() will fail. | ||
// | ||
// The root cause of this issue is that before PerIsolateMessageListener() | ||
// is invoked by v8, v8 preserves the vm state, which is JS. However, | ||
// SetIdle() requires the vm state is either EXTERNEL or IDLE when embedder | ||
// calling it. | ||
|
||
if (process.argv[2] === 'child') { | ||
const { Worker } = require('worker_threads'); | ||
new Worker('', { eval: true }); | ||
throw new Error('xxx'); | ||
} else { | ||
const assert = require('assert'); | ||
const { spawnSync } = require('child_process'); | ||
const result = spawnSync(process.execPath, [__filename, 'child']); | ||
|
||
const stderr = result.stderr.toString().trim(); | ||
// Expect error message to be preserved | ||
assert.match(stderr, /xxx/); | ||
// Expect no crash message | ||
assert.doesNotMatch(stderr, /node::DumpBacktrace/); | ||
} |