summaryrefslogtreecommitdiff
path: root/runtime/js/99_main.js
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2024-03-11 22:18:03 +0000
committerGitHub <noreply@github.com>2024-03-11 23:18:03 +0100
commitd69aab62b0789dd54b8c09b54af022a38f060b5b (patch)
treee99a5a3217d6aeee379bc592bfa33702dc2d6de8 /runtime/js/99_main.js
parent28b362adfc49324e20af5ecb1530f89eb91c4ed5 (diff)
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>
Diffstat (limited to 'runtime/js/99_main.js')
-rw-r--r--runtime/js/99_main.js12
1 files changed, 11 insertions, 1 deletions
diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js
index 82e444dfd..27ba488e7 100644
--- a/runtime/js/99_main.js
+++ b/runtime/js/99_main.js
@@ -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,
+ );
}
}