事件:'disconnect'


【Event: 'disconnect'

在工作线程 IPC 通道断开连接后触发。当工作线程正常退出、被终止,或被手动断开连接(例如使用 worker.disconnect())时,可能会发生这种情况。

【Emitted after the worker IPC channel has disconnected. This can occur when a worker exits gracefully, is killed, or is disconnected manually (such as with worker.disconnect()).】

'disconnect' 和 'exit' 事件之间可能存在延迟。这些事件可用于检测进程是否卡在清理阶段,或者是否存在长连接。

【There may be a delay between the 'disconnect' and 'exit' events. These events can be used to detect if the process is stuck in a cleanup or if there are long-living connections.】

cluster.on('disconnect', (worker) => {
  console.log(`The worker #${worker.id} has disconnected`);
});