summaryrefslogtreecommitdiff
path: root/ext/node
diff options
context:
space:
mode:
authorSatya Rohith <me@satyarohith.com>2024-03-14 01:22:53 +0530
committerGitHub <noreply@github.com>2024-03-13 19:52:53 +0000
commitbbc211906dcd5043af549250343cd7b42fb45043 (patch)
tree49868b4b758290dcec6668f95495ce9d79ad6a86 /ext/node
parent0fd8f549e2194223eca2d4b17f4e96cd5a0f5fd5 (diff)
fix(ext/node): make worker ids sequential (#22884)
Diffstat (limited to 'ext/node')
-rw-r--r--ext/node/polyfills/02_init.js7
-rw-r--r--ext/node/polyfills/worker_threads.ts7
2 files changed, 9 insertions, 5 deletions
diff --git a/ext/node/polyfills/02_init.js b/ext/node/polyfills/02_init.js
index 04820b837..85f924493 100644
--- a/ext/node/polyfills/02_init.js
+++ b/ext/node/polyfills/02_init.js
@@ -14,6 +14,7 @@ function initialize(
usesLocalNodeModulesDir,
argv0,
runningOnMainThread,
+ workerId,
maybeWorkerMetadata,
) {
if (initialized) {
@@ -39,7 +40,11 @@ function initialize(
// FIXME(bartlomieju): not nice to depend on `Deno` namespace here
// but it's the only way to get `args` and `version` and this point.
internals.__bootstrapNodeProcess(argv0, Deno.args, Deno.version);
- internals.__initWorkerThreads(runningOnMainThread, maybeWorkerMetadata);
+ internals.__initWorkerThreads(
+ runningOnMainThread,
+ workerId,
+ maybeWorkerMetadata,
+ );
internals.__setupChildProcessIpcChannel();
// `Deno[Deno.internal].requireImpl` will be unreachable after this line.
delete internals.requireImpl;
diff --git a/ext/node/polyfills/worker_threads.ts b/ext/node/polyfills/worker_threads.ts
index 4563f157f..49f2f3e3e 100644
--- a/ext/node/polyfills/worker_threads.ts
+++ b/ext/node/polyfills/worker_threads.ts
@@ -134,7 +134,6 @@ function toFileUrl(path: string): URL {
: toFileUrlPosix(path);
}
-let threads = 0;
const privateWorkerRef = Symbol("privateWorkerRef");
class NodeWorker extends EventEmitter {
#id = 0;
@@ -195,12 +194,10 @@ class NodeWorker extends EventEmitter {
name = "[worker eval]";
}
this.#name = name;
- this.threadId = ++threads;
const serializedWorkerMetadata = serializeJsMessageData({
workerData: options?.workerData,
environmentData: environmentData,
- threadId: this.threadId,
}, options?.transferList ?? []);
const id = op_create_worker(
{
@@ -216,6 +213,7 @@ class NodeWorker extends EventEmitter {
serializedWorkerMetadata,
);
this.#id = id;
+ this.threadId = id;
this.#pollControl();
this.#pollMessages();
// https://nodejs.org/api/worker_threads.html#event-online
@@ -391,6 +389,7 @@ let parentPort: ParentPort = null as any;
internals.__initWorkerThreads = (
runningOnMainThread: boolean,
+ workerId,
maybeWorkerMetadata,
) => {
isMainThread = runningOnMainThread;
@@ -414,11 +413,11 @@ internals.__initWorkerThreads = (
>();
parentPort = self as ParentPort;
+ threadId = workerId;
if (maybeWorkerMetadata) {
const { 0: metadata, 1: _ } = maybeWorkerMetadata;
workerData = metadata.workerData;
environmentData = metadata.environmentData;
- threadId = metadata.threadId;
}
defaultExport.workerData = workerData;
defaultExport.parentPort = parentPort;