-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
worker: ignore --abort-on-uncaught-exception for terminate()
When running Worker threads with `--abort-on-uncaught-exception`, do not abort the process when `worker.terminate()` is called. PR-URL: #26111 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
- Loading branch information
Showing
3 changed files
with
39 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
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'); | ||
const { spawn } = require('child_process'); | ||
const { Worker } = require('worker_threads'); | ||
|
||
// Tests that --abort-on-uncaught-exception applies to workers as well. | ||
|
||
if (process.argv[2] === 'child') { | ||
new Worker('throw new Error("foo");', { eval: true }); | ||
return; | ||
} | ||
|
||
const child = spawn(process.execPath, [ | ||
'--abort-on-uncaught-exception', __filename, 'child' | ||
]); | ||
child.on('exit', common.mustCall((code, sig) => { | ||
if (common.isWindows) { | ||
assert.strictEqual(code, 0xC0000005); | ||
} else { | ||
assert(['SIGABRT', 'SIGTRAP', 'SIGILL'].includes(sig), | ||
`Unexpected signal ${sig}`); | ||
} | ||
})); |
12 changes: 12 additions & 0 deletions
12
test/parallel/test-worker-abort-on-uncaught-exception-terminate.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,12 @@ | ||
// Flags: --abort-on-uncaught-exception | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const { Worker } = require('worker_threads'); | ||
|
||
// Tests that --abort-on-uncaught-exception does not apply to | ||
// termination exceptions. | ||
|
||
const w = new Worker('while(true);', { eval: true }); | ||
w.on('online', common.mustCall(() => w.terminate())); | ||
w.on('exit', common.mustCall((code) => assert.strictEqual(code, 1))); |