Skip to content

fix(docker): run node under tini instead of npm to silence shutdown noise#4222

Open
Danswar wants to merge 1 commit into
developfrom
fix/tini-pid1-shutdown-noise
Open

fix(docker): run node under tini instead of npm to silence shutdown noise#4222
Danswar wants to merge 1 commit into
developfrom
fix/tini-pid1-shutdown-noise

Conversation

@Danswar

@Danswar Danswar commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Why

Every container stop — each release deploy plus every restart — logs npm's 5-line npm error ... signal SIGTERM / command failed block at ERROR level. Verified 1:1 over the last 7 days: all five develop→main releases produced the block ~6 minutes after merge, and the chronic restarts produce it too (~80 blocks/week across prd+dev). It's pure noise: npm complaining that its child died from the signal it was just sent.

What

  • RUN apk add --no-cache tini + ENTRYPOINT ["/sbin/tini", "--"] in the runtime stage.
  • CMD ["node", "--max-old-space-size=6144", "dist/src/main"] — inlines exactly what start:prod runs.

Why tini instead of bare node

The app registers no SIGTERM/SIGINT handler (no enableShutdownHooks(); only an uncaughtException handler in main.ts). Bare node as PID 1 would therefore ignore SIGTERM (PID-1 signal semantics: default dispositions don't apply) and get SIGKILLed after the stop-grace period — slowing every deploy and ending in an uncatchable kill. tini as PID 1 forwards SIGTERM to node running as a normal child, which exits immediately — byte-identical stop behavior to today, minus the npm noise.

Introducing actual graceful shutdown (enableShutdownHooks() + auditing all long-lived handles so the event loop can drain) is deliberately out of scope — it's a behavior change that deserves its own tested PR.

Verified before inlining start:prod

  • start:prod wraps nothing but the node invocation (no pre/post lifecycle hooks — only prebuild exists).
  • No code under src/ reads npm-injected env (npm_package_*, npm_config_*, npm_lifecycle_*).
  • Neither dfxdev nor dfxprd compose overrides command:/entrypoint: for the dfx-api service, so the Dockerfile CMD is authoritative in both deployments.

Post-deploy check

First stop after this image rolls out (next deploy or restart): zero npm error lines in Loki for the stop event; container stop latency unchanged.

…oise

Every container stop (each release deploy + every restart) logs npm's
5-line 'command failed / signal SIGTERM' ERROR block - npm watching its
child die is pure noise, ~80 blocks/week across prd+dev.

tini as PID 1 forwards SIGTERM to node, which exits immediately exactly
as it did under npm (the app has no shutdown hooks; stop behavior is
byte-identical). Bare node as PID 1 was NOT an option: with no SIGTERM
handler and PID-1 signal semantics it would ignore the signal and be
SIGKILLed after the grace period, slowing every deploy.

start:prod wraps nothing but the node invocation (no pre/post hooks,
no npm env consumed anywhere in src/) - verified before inlining it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant