ERR_SERVER_NOT_RUNNING node cluster ai_generated true

Error [ERR_SERVER_NOT_RUNNING]: Server is not running.

ID: node/node-cluster-disconnect

Also available as: JSON · Markdown
85%Fix Rate
88%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
20 active

Root Cause

A cluster worker disconnected unexpectedly from the master process, usually due to an unhandled exception, memory exhaustion, or explicit disconnect call before the server was ready.

generic

Workarounds

  1. 90% success Listen for 'disconnect' and 'exit' events on the cluster and fork replacement workers
    cluster.on('exit', (worker, code) => { if (!worker.exitedAfterDisconnect) cluster.fork(); });

    Sources: https://nodejs.org/api/cluster.html#event-exit

  2. 88% success Implement graceful shutdown with server.close() before disconnecting
    In the worker: server.close(() => { process.disconnect(); }); — ensures all connections drain before exiting

    Sources: https://nodejs.org/api/cluster.html#workerdisconnect

Dead Ends

Common approaches that don't work:

  1. Calling cluster.disconnect() before workers have fully initialized 75% fail

    Workers that haven't bound to a port yet will silently fail to clean up, leaving orphaned connections

  2. Using process.exit() in workers instead of graceful shutdown 80% fail

    Abrupt exit drops in-flight requests and can corrupt shared state or IPC channels

Error Chain

Leads to:
Preceded by:
Frequently confused with: