-
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.
workers: fix spawning from preload scripts
Fix spawning nested worker threads from preload scripts and warn about doing so. Signed-off-by: James M Snell <[email protected]> Fixes: #36531 PR-URL: #37481 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
- Loading branch information
Showing
4 changed files
with
35 additions
and
4 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
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,9 @@ | ||
const { | ||
Worker, | ||
workerData, | ||
threadId | ||
} = require('worker_threads'); | ||
|
||
if (threadId < 2) { | ||
new Worker('1 + 1', { eval: true }); | ||
} |
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,10 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const fixtures = require('../common/fixtures'); | ||
const worker = fixtures.path('worker-preload.js'); | ||
const { exec } = require('child_process'); | ||
const kNodeBinary = process.argv[0]; | ||
|
||
|
||
exec(`"${kNodeBinary}" -r "${worker}" -pe "1+1"`, common.mustSucceed()); |