Diagnose Requests Dropped During Deploys From Shutdown Order, Signal Handling, and Drain Timing
You are helping me diagnose why a service drops or fails requests while it is being deployed, restarted or scaled down. Users or upstream callers see errors such as 502, 503, connection reset or "upstream closed connection" in a short window around each rollout, and the service is healthy otherwise. I will provide whatever I have: the deploy or orchestrator config (for example the Kubernetes Deployment with its probes, preStop hook and terminationGracePeriodSeconds), the load balancer or proxy config, the application's signal handling and shutdown code, and timestamps of errors relative to deploy events. Work through the shutdown sequence in order and, for each step, say what should happen, what my config makes happen, and where requests can be lost: 1. Stop routing new traffic: how long does it take the load balancer, service mesh or DNS to stop sending to the old instance after shutdown begins? Does the app keep accepting connections during that gap, or does it exit or close its listener first? 2. Signal handling: does the process actually receive SIGTERM (watch for shell-form entrypoints that don't forward signals), and does it stop accepting new work while finishing in-flight requests? 3. Draining: are keep-alive connections closed gracefully, and are long requests, streams, WebSockets and background jobs given a deadline? 4. Hard kill: is the grace period longer than the drain plus the routing delay, or does the process get SIGKILLed mid-request? 5. Startup side: is the new instance marked ready before it can really serve, for example before caches warm or connections to dependencies open? Then rank the likely causes by how well they match the error timing I gave, and propose one experiment per cause that would confirm or rule it out, cheapest first. Do not recommend raising timeouts everywhere as a fix; tie every change to a specific step above. --- When to use it: when error spikes line up with deploys, autoscaling scale-downs, node drains or restarts, and the app looks fine the rest of the time. How to adapt it: replace the Kubernetes terms with your platform's equivalents (ECS stopTimeout, systemd TimeoutStopSec, a PaaS's shutdown window). If you have errors only at startup or only at shutdown, say which; that halves the search. Example input: a Deployment with no preStop hook and a 30-second grace period, a Node.js server that calls process.exit() on SIGTERM, and 502s from the ingress during the first two seconds of each pod's termination. Good output identifies that the process exits immediately while the ingress is still routing to it. It suggests handling SIGTERM by stopping new connections and finishing in-flight requests, plus a short preStop delay so routing updates first. The confirming experiment is to compare per-pod error timestamps against endpoint-removal events. Weak output is a generic list of "check your health checks."
Sign in to upvote this prompt.