Skip to content

node-cluster preset: primary does not forward SIGTERM to workers — graceful shutdown broken under Kubernetes/Docker #4723

Closed

Description

@GuillaumeAmat

Environment

  • Nitro: latest 2.x (2.13.4) and current main (v3)
  • Preset: node-cluster
  • Runtime: Kubernetes / Docker (docker stop)

Describe the bug

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:

  1. Forward the signal to each alive worker (worker.process.kill(signal)) so their srvx graceful shutdown drains in-flight requests.
  2. Exit once all workers are dead (cluster.on('exit') drain-watch), or force-exit after NITRO_SHUTDOWN_TIMEOUT.
  3. (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

  1. added
    bug
    on Oct 15, 2026
  2. added theissue type on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpreset:node

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions