On every deploy, the platform sends your Node.js process SIGTERM and, after a grace period, SIGKILL . If the process exits immediately, requests in progress fail; if it calls server.close() and waits, idle keep-alive connections can hold it open until the kill. A graceful shutdown does four things in order: fail the readiness check and wait a few seconds so the load balancer stops sending traffic; stop accepting connections and close idle keep-alive sockets ; let in-flight requests finish ; and force-close whatever remains before the platform's deadline. Here's a tested implementation with node:http and nothing else.
Why isn't server.close() enough?
server.close() stops new connections and waits for existing ones to end. Two problems:
Keep-alive. Clients reuse connections, and on Node.js 18 an idle keep-alive socket keeps close() waiting with nothing actually happening.…