'disconnect' 事件


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

'disconnect''exit' 事件之间可能存在延迟。 这些事件可用于检测进程是否陷入清理或是否存在长期连接。

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

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()).

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`);
});