From 67404465ee0eac7696db83b463ce65c15addcb75 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sun, 22 Nov 2026 21:59:46 +0000 Subject: [PATCH] src: expand --process-timeout output to include workers When a process is interrupted using `--process-timeout`, the output would print the resources and stack of the main thread. If the thing keeping the process alive was a worker thread, or if the worker thread was interrupted, there was no diagnostic output. This adds an additional `--process-timeout-worker-stacks` flag that includes the worker details. We don't necessarily want to include workers every time because if there's a large number of workers the output could become quite noisy. Signed-off-by: James M Snell Assisted-by: Claude --- doc/api/cli.md | 48 ++++- doc/node.1 | 37 +++- src/node_options.cc | 8 + src/node_options.h | 1 + src/node_watchdog.cc | 180 ++++++++++++++++-- test/parallel/test-process-timeout-options.js | 24 ++- .../test-process-timeout-worker-stacks.js | 111 +++++++++++ 7 files changed, 379 insertions(+), 30 deletions(-) create mode 100644 test/parallel/test-process-timeout-worker-stacks.js diff --git a/doc/api/cli.md b/doc/api/cli.md index a4e27926b00c..1decf37bdc24 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -2716,6 +2716,48 @@ changes: Identical to `-e` but prints the result. +### `--process-timeout-worker-stacks` + + + +> Stability: 1.1 - Active development + +When [`--process-timeout`][] expires, also prints what each [`Worker`][] thread, +including Workers created by other Workers, was doing and which resources were +keeping its event loop alive to stderr, after the summary for the main thread: + +```console +$ node --process-timeout=5s --process-timeout-worker-stacks app.js +(node:25418) Process timed out after 5s (--process-timeout). Exiting with code 124. +Main thread was not executing JavaScript. +Resources keeping the event loop alive: + Worker (thread 2, name 'WorkerThread') + Worker (thread 1, name 'compute') +Worker thread 1 (name 'compute') was executing JavaScript: + at spin (/home/user/compute.js:3:3) + at /home/user/compute.js:6:1 + at node:internal/modules/cjs/loader:1989:14 + at node:internal/modules/cjs/loader:2129:10 + at node:internal/modules/cjs/loader:1711:32 + at node:internal/modules/cjs/loader:1501:12 + at wrapModuleLoad (node:internal/modules/cjs/loader:261:19) + at executeUserEntryPoint (node:internal/modules/run_main:166:5) + at node:internal/main/worker_thread:247:26 + at [nodejs.internal.kHybridDispatch] (node:internal/event_target:876:20) +No resources keeping its event loop alive were found. +Worker thread 2 (name 'WorkerThread') was not executing JavaScript. +Resources keeping its event loop alive: + Timeout (next due in 28ms) +``` + +Worker threads that do not respond within two seconds, for example because +they are blocked in a synchronous operation such as +[`child_process.execSync()`][], are listed without a stack trace or +resources. Requires +[`--process-timeout`][]. + ### `--process-timeout=duration`