--process-timeout=duration
如果从进程启动时起经过 duration,进程仍在运行,则以代码 124 退出。duration 是一个正整数,后面跟一个单位:ms、s、m 或 h,例如 500ms、30s、5m 或 1h。退出代码与 timeout(1) 命令使用的代码相同。
🌐 Exits the process with code 124 if it is still running after duration,
measured from the start of the process. duration is a positive integer
followed by a unit: ms, s, m, or h, for example 500ms, 30s, 5m, or
1h. The exit code matches the one used by the timeout(1) command.
在退出之前,Node.js 会把主线程在做什么以及哪些资源在让事件循环保持活跃打印到标准错误输出:
🌐 Before exiting, Node.js prints what the main thread was doing and which resources were keeping the event loop alive to stderr:
$ node --process-timeout=5s server.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:
TCPServerWrap (listening on [::]:3000, fd 20)
Timeout x2 (next due in 2931ms) 如果主线程正在执行 JavaScript,则会打印其堆栈跟踪。使用 --report-on-process-timeout 也可以生成一个 诊断报告。
🌐 If the main thread was executing JavaScript, its stack trace is printed instead.
Use --report-on-process-timeout to also generate a diagnostic report.
该进程在没有触发 'beforeExit' 和 'exit' 事件的情况下退出,因为 JavaScript 代码可能是让进程保持运行的原因。代码覆盖率和性能分析,例如使用 NODE_V8_COVERAGE=dir 或 --cpu-prof 启用的,仍然会被写入。
🌐 The process exits without emitting the 'beforeExit' and 'exit' events, as
the JavaScript code may be what keeps the process running. Code coverage and
profiles, such as those enabled with NODE_V8_COVERAGE=dir or
--cpu-prof, are still written.
如果主线程在两秒内没有响应,例如因为它被某个同步操作(比如 child_process.execSync())阻塞,Node.js 会立即退出,而不会打印堆栈跟踪和资源信息。
🌐 If the main thread does not respond within two seconds, for example because it
is blocked in a synchronous operation such as child_process.execSync(),
Node.js exits immediately without printing the stack trace and resources.
在 NODE_OPTIONS 中不允许使用此选项,而且它不能与启用检查器的选项组合使用,比如 --inspect、--inspect-brk、--inspect-wait、--inspect-port 和 --inspect-publish-uid,也不能与 node inspect、--run 或 --build-snapshot 一起使用。在它生效期间,inspector.open() 和 session.connectToMainThread() 会抛出错误,而且用 SIGUSR1 激活检查器的请求会被忽略。
🌐 This option is not allowed in NODE_OPTIONS, and it cannot be combined
with the options that enable the inspector, such as --inspect,
--inspect-brk, --inspect-wait, --inspect-port, and
--inspect-publish-uid, nor with node inspect, --run, or
--build-snapshot. While it is in effect, inspector.open() and
session.connectToMainThread() throw, and requests to activate the
inspector with SIGUSR1 are ignored.
继承了 process.execArgv 的子进程,比如用 child_process.fork() 创建的,会从它们自己的启动时间开始应用超时。使用 --watch 时,超时应用于应用的每次运行,而不是用于监视变化的进程。使用 从命令行运行测试 时,测试运行器进程会对整个运行应用超时,每个在自己进程中运行的测试文件也会应用超时。
🌐 Child processes that inherit process.execArgv, such as those created with
child_process.fork(), apply the timeout from their own start. With
--watch, the timeout applies to each run of the application rather than
to the process that watches for changes. When
running tests from the command line, the test runner process applies the
timeout to the whole run, and each test file that runs in its own process
applies it as well.