From 48e8b86625a769aaa71508d8e040493df866f5d7 Mon Sep 17 00:00:00 2001 From: Paolo Insogna Date: Fri, 20 Nov 2026 07:53:49 +0100 Subject: [PATCH] worker: add diagnostic channel 'worker_threads.main.registry' Signed-off-by: Paolo Insogna Assisted-By: OpenAI:GPT-6.1 Sol PR-URL: https://github.com/nodejs/node/pull/67311 Reviewed-By: Matteo Collina Reviewed-By: James M Snell --- doc/api/diagnostics_channel.md | 14 +++ lib/internal/worker/messaging.js | 17 ++++ ...nostics-channel-worker-threads-registry.js | 87 +++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 test/parallel/test-diagnostics-channel-worker-threads-registry.js diff --git a/doc/api/diagnostics_channel.md b/doc/api/diagnostics_channel.md index 242f8259c87..c40feab5dae 100644 --- a/doc/api/diagnostics_channel.md +++ b/doc/api/diagnostics_channel.md @@ -2021,6 +2021,20 @@ added: v16.18.0 Emitted when a new thread is created. +##### Event: `'worker_threads.main.registry'` + +* `threadIds` {number\[]} A snapshot of the registered worker thread IDs. + +Emitted only on the main thread whenever the worker thread registry changes, +including workers created by other workers. Each event contains a snapshot of +the registered worker thread IDs. The main thread's ID (`0`) is not included. + +The registry tracks workers through their internal messaging ports. Registration +can occur before a worker is online. Removal occurs when the parent thread +processes the worker's exit and can be delayed if the parent thread is blocked. +Consequently, a snapshot does not guarantee that every listed worker is ready or +still running. + #### SQLite