My default Node.js graceful shutdown was short. Listen for SIGTERM, call server.close() , wait for the callback, exit. It looks complete, and I'd have pasted it into a service without a second thought.
So I measured it. I built a small lab, pointed 200 requests per second at four different servers, sent SIGTERM mid-flight, and counted every request that didn't come back with a 200.
server.close() saved the requests already in flight, and in my tests that was all it reliably saved. Four other assumptions sit around that one fact (your test client, your load balancer, your keep-alive timeout and the way your container starts), and each one changed the result. Here are the five, with the numbers.
Mistake What I measured
1. Treating server.close() as the whole shutdown 0 in-flight requests lost, but new connections were refused
2. Testing with a client that reuses connections Plain node:http failed 7 requests with a pooled client and 200 with a fresh connection per request
3.…