From a6872fddfa2c60b3fffbac8eaf65f96bcc14b7c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 29 Sep 2023 09:31:29 +0200 Subject: [PATCH 1/2] Debug --- ext/node/polyfills/worker_threads.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ext/node/polyfills/worker_threads.ts b/ext/node/polyfills/worker_threads.ts index 5d999f7af9eadd..396e9cd5d9afd0 100644 --- a/ext/node/polyfills/worker_threads.ts +++ b/ext/node/polyfills/worker_threads.ts @@ -203,10 +203,13 @@ type ParentPort = typeof self & NodeEventTarget; // deno-lint-ignore no-explicit-any let parentPort: ParentPort = null as any; +core.print(`worker_threads ${isMainThread} ${!parentPort}\n`); + globalThis.__bootstrap.internals.__initWorkerThreads = () => { isMainThread = // deno-lint-ignore no-explicit-any (globalThis as any).name !== PRIVATE_WORKER_THREAD_NAME; + console.log("isMainThread", isMainThread, globalThis.name); defaultExport.isMainThread = isMainThread; // fake resourceLimits @@ -219,13 +222,15 @@ globalThis.__bootstrap.internals.__initWorkerThreads = () => { defaultExport.resourceLimits = resourceLimits; if (!isMainThread) { + console.log("in not main thread", !self); // deno-lint-ignore no-explicit-any delete (globalThis as any).name; + console.log("here2"); // deno-lint-ignore no-explicit-any const listeners = new WeakMap<(...args: any[]) => void, (ev: any) => any>(); parentPort = self as ParentPort; - + console.log("parentPort is not main thread", !parentPort); const initPromise = once( parentPort, "message", From d549d20d872978fba1fed3f64a2c56b02b79665b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 4 Oct 2023 23:25:13 +0200 Subject: [PATCH 2/2] update parentPort after starting a worker --- ext/node/polyfills/worker_threads.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/node/polyfills/worker_threads.ts b/ext/node/polyfills/worker_threads.ts index 396e9cd5d9afd0..793beb75b91b1d 100644 --- a/ext/node/polyfills/worker_threads.ts +++ b/ext/node/polyfills/worker_threads.ts @@ -230,6 +230,7 @@ globalThis.__bootstrap.internals.__initWorkerThreads = () => { const listeners = new WeakMap<(...args: any[]) => void, (ev: any) => any>(); parentPort = self as ParentPort; + defaultExport.parentPort = parentPort; console.log("parentPort is not main thread", !parentPort); const initPromise = once( parentPort,