mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
fix(ext/node): make worker setup synchronous (#22815)
This commit fixes race condition in "node:worker_threads" module were the first message did a setup of "threadId", "workerData" and "environmentData". Now this data is passed explicitly during workers creation and is set up before any user code is executed. Closes https://github.com/denoland/deno/issues/22783 Closes https://github.com/denoland/deno/issues/22672 --------- Co-authored-by: Satya Rohith <me@satyarohith.com>
This commit is contained in:
parent
28b362adfc
commit
d69aab62b0
6 changed files with 60 additions and 46 deletions
|
@ -786,6 +786,7 @@ function bootstrapWorkerRuntime(
|
|||
runtimeOptions,
|
||||
name,
|
||||
internalName,
|
||||
maybeWorkerMetadata,
|
||||
) {
|
||||
if (hasBootstrapped) {
|
||||
throw new Error("Worker runtime already bootstrapped");
|
||||
|
@ -908,8 +909,17 @@ function bootstrapWorkerRuntime(
|
|||
// existing global `Deno` with `Deno` namespace from "./deno.ts".
|
||||
ObjectDefineProperty(globalThis, "Deno", core.propReadOnly(finalDenoNs));
|
||||
|
||||
const workerMetadata = maybeWorkerMetadata
|
||||
? messagePort.deserializeJsMessageData(maybeWorkerMetadata)
|
||||
: undefined;
|
||||
|
||||
if (nodeBootstrap) {
|
||||
nodeBootstrap(hasNodeModulesDir, argv0, /* runningOnMainThread */ false);
|
||||
nodeBootstrap(
|
||||
hasNodeModulesDir,
|
||||
argv0,
|
||||
/* runningOnMainThread */ false,
|
||||
workerMetadata,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue