You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
node-cluster preset: primary does not forward SIGTERM to workers — graceful shutdown broken under Kubernetes/Docker #4723
Under orchestrators that signal only PID 1 (Kubernetes pod termination, docker stop), the node-cluster preset cannot shut down gracefully, because the cluster primary never forwards SIGTERM/SIGINT to its forked workers:
2.x (presets/node/runtime/node-cluster.mjs): the master traps the signal, sets isShuttingDown, and waits for workers to drain — but nothing ever signals the workers. They keep serving in-flight and new requests until the 30s timeout, then process.exit(0) on the master → kubelet sends SIGKILL to the whole pod, dropping in-flight requests. Net effect: every shutdown burns the full termination grace period and still ends in a hard kill.
v3 / main (presets/node/cluster.ts generates a master entry that only forks workers): there is no primary-side signal handling at all (also no respawn of crashed workers).
Each worker does have correct per-process graceful shutdown (srvx gracefulShutdownPlugin in 2.x, setupCloseHooks in v3) — it just never receives the signal, since Node does not forward signals from a parent to cluster workers, and docker/k8s only signal PID 1.
For contrast, this works under supervisors that signal the whole process group (systemd KillMode=control-group, Ctrl+C on a foreground group, PM2) which is likely why it goes unnoticed. PR #1227 already acknowledged the equivalent gap for nitro-dev ("implemented using cluster messaging since signals are not available to Node workers").
Expected behavior
On SIGTERM/SIGINT in the primary:
Forward the signal to each alive worker (worker.process.kill(signal)) so their srvx graceful shutdown drains in-flight requests.
Exit once all workers are dead (cluster.on('exit') drain-watch), or force-exit after NITRO_SHUTDOWN_TIMEOUT.
(Optionally, separately) respawn workers on unexpected exit with backoff.
Reproduction
NITRO_PRESET=node-cluster nitro build .&& node .output/server/index.mjs &# with a slow (>1s) in-flight request:
curl localhost:3000/slow &kill -TERM <primary pid># like k8s/docker does
2.x: logs nothing, request still being served, 30s later workers die hard.
v3: primary exits (or lingers) while workers keep running/being killed hard.
For k8s specifically the receiving end of the forwarded SIGTERM in each worker is already correct — the missing piece is only the forwarding + drain-coordination in the primary.
Activity