13 / 17

What happens when a worker process crashes in a Node.js cluster?

When a worker crashes, the master process receives an 'exit' event. You can listen to this event and call cluster.fork() to automatically respawn a new worker, ensuring high availability of the application.

Worker crashes are a natural occurrence in production environments. The Cluster module provides the 'exit' event on the cluster object that fires whenever a worker dies. You must explicitly handle this event and fork a new worker — Node.js does NOT automatically restart crashed workers without your intervention.

Auto-Restarting Crashed Workers
Exit Event Properties
  1. 1

    worker — the Worker object that exited

  2. 2

    code — the exit code (0 = clean exit, non-zero = error)

  3. 3

    signal — the signal that killed the process (e.g., SIGKILL)

  4. 4

    worker.exitedAfterDisconnect — true if intentionally disconnected, false if crashed