From d69aab62b0789dd54b8c09b54af022a38f060b5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 11 Mar 2024 22:18:03 +0000 Subject: 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 --- runtime/ops/worker_host.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'runtime/ops') diff --git a/runtime/ops/worker_host.rs b/runtime/ops/worker_host.rs index ee9f0dc5e..d1b318f0f 100644 --- a/runtime/ops/worker_host.rs +++ b/runtime/ops/worker_host.rs @@ -35,6 +35,7 @@ pub struct CreateWebWorkerArgs { pub permissions: PermissionsContainer, pub main_module: ModuleSpecifier, pub worker_type: WebWorkerType, + pub maybe_worker_metadata: Option, } pub type CreateWebWorkerCb = dyn Fn(CreateWebWorkerArgs) -> (WebWorker, SendableWebWorkerHandle) @@ -121,6 +122,7 @@ pub struct CreateWorkerArgs { fn op_create_worker( state: &mut OpState, #[serde] args: CreateWorkerArgs, + #[serde] maybe_worker_metadata: Option, ) -> Result { let specifier = args.specifier.clone(); let maybe_source_code = if args.has_source_code { @@ -189,6 +191,7 @@ fn op_create_worker( permissions: worker_permissions, main_module: module_specifier.clone(), worker_type, + maybe_worker_metadata, }); // Send thread safe handle from newly created worker to host thread -- cgit v1.2.3