What this thread does
Do first: start with node --unhandled-rejections=strict server.js, then identify the platform kill deadline before choosing the application's drain budget.
Short answer
As of November 2026, this card targets Node.js 26.13.1 LTS (November 11 release) and the 26.x API reference. Own each promise with await/catch or an explicit background-task supervisor. On ordinary SIGTERM, stop admission, drain accepted work, close dependencies, then let the event loop finish; one deadline bounds the entire sequence.
Choose / don't choose
throw: choose the default when unhandled rejections should become uncaught exceptions unless anunhandledRejectionhandler exists. Don't attach a logging-only handler that unintentionally keeps serving after a fatal rejection.strict: choose when unhandled rejection is raised as an uncaught exception. Don't use uncaught exceptions to continue normal service; Node advises synchronous cleanup and an external restart (CLI, process API). Fatal crash cleanup differs from an ordinary graceful SIGTERM.- Bounded graceful drain: choose for normal restarts; don't promise completion beyond the orchestrator's SIGKILL deadline. Upgraded sockets and independent queue jobs need their own tracking.
Not for: HTTP response double-send errors; see node-err-http-headers-sent-write-after-end-diagnostic.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
--unhandled-rejections | Modes: throw (default since 15.0.0), strict, warn, warn-with-error-code, none; choose strict or deliberate throw for a fatal policy | Node 26.x | CLI |
server.close() | Call once to stop accepting connections and await HTTP drain; idle connections are reaped since 19.0.0 | Node 26.x | HTTP |
server.closeIdleConnections() | For older compatibility, call after close(); redundant for idle keep-alive reaping on 19+ | Added 18.2.0 | HTTP |
server.closeAllConnections() | Only after close() at the hard deadline; destroys active HTTP connections, not upgraded WebSocket or HTTP/2 sockets | Added 18.2.0 | HTTP |
server.keepAliveTimeout | Set explicitly to the service's idle-reuse policy; it is not a bound on handler execution. The reference lists 65000 for server.keepAliveTimeout. | Node 26.x | HTTP |
server.headersTimeout | Default min(requestTimeout, 60000) ms; bounds incoming headers, not an active handler's database call | Since 19.4.0 / 18.14.0 | HTTP |
terminationGracePeriodSeconds | Kubernetes default 30 seconds; preStop consumes this budget too. The question's terminationGradePeriodSeconds spelling is invalid. | Pod lifecycle | Kubernetes |
--timeout on container stop | Default 10 seconds on Linux, 30 on Windows unless configured; -1 waits indefinitely | Docker container stop | Docker |
warn always warns; warn-with-error-code warns and sets exit code 1 only without the event handler; none silences warnings. Static ES module entry-point rejection always raises an uncaught exception (CLI).
Order of operations
1. Catch expected request failures where a response/retry decision can be made. Track background promises explicitly so HTTP completion is not mistaken for completion of accepted work. Await cleanup promises; an async exit listener cannot finish them (process API). 2. On the first SIGTERM, enter an idempotent draining state, fail readiness and stop queue intake/scheduled producers. Call server.close(); reject new application work arriving through already accepted connections while retaining dependencies for active requests. 3. Start one absolute application deadline shorter than the remaining kill budget. Illustrative policy: 20 seconds total with Kubernetes' 30-second grace only if preStop and scheduling leave that margin; 8 seconds for Docker's default Linux 10 seconds. These are application choices, not Node defaults. Include pool closure and log flush time, not just HTTP drain (Kubernetes, Docker). 4. Await active HTTP requests and tracked jobs while dependencies remain usable. Then close database pools, queue clients, outbound agents and timers. Account separately for upgraded protocols. Clear the deadline timer after all cleanup settles. 5. Successful intentional shutdown sets process.exitCode = 0 and lets the loop empty. Cleanup failure/deadline sets 1; at the deadline, force-close remaining HTTP connections and terminate if remaining resources cannot be stopped. Immediate process.exit() can truncate output, so reserve it for the final enforced boundary. Keep the deadline mechanism active through required cleanup (process API).
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
HTTP server.close() does not shut down, process hangs | ZebraNorth reported this hang on 16.7.0/17.4.0, distinct from an in-flight request or idle socket | Reproduce lifecycle ordering, avoid closing before listening completes, and inspect process.getActiveResourcesInfo() for remaining resource types; close the owning pool/timer/socket | February 8, 2022 report, resource API |
ECONNRESET | Server closure during socket reuse can cause ECONNRESET; closeAllConnections closes active HTTP(S) connections | Distinguish idle timeout from hard deadline; preserve active requests until the deadline and configure the documented keep-alive buffer | HTTP |
The resource API reports types, not each handle's creation stack. Add ownership instrumentation around the remaining pool, socket or timer. Do not use undocumented private handle APIs as the first diagnostic.
Missing
- The actual platform deadline and longest legitimate task are unspecified; no universal drain timeout follows from Node alone.
- The 26.x HTTP property text still lists 5000 ms while the reference lists 65000 for keepAliveTimeout. Pimterry's April 16, 2026 change raises the keepAliveTimeout default to 65 seconds; set it explicitly and inspect the deployed instance instead of relying on conflicting text.
Checked
2026-11-23; Node.js 26.13.1 LTS; release, CLI/HTTP/process references, Kubernetes and Docker references, ZebraNorth report and pimterry change rechecked. No service or shutdown commands executed.
Started from a post by @Node.js, packaged by the editor. Original post