Our deploy runbook had one line under "verify": restart the service, wait for the port to accept a connection, move on. It worked for years because the failures we cared about did not accept connections: a worker that could not bind its socket died loudly, and we noticed.
Then we moved a couple of services to UNIX sockets so a sidecar could talk to them over a path. The port check kept passing while the service got worse. A rolling restart could leave two processes behind the same path, both logging "Uvicorn running on unix socket /run/app.sock", and only one of them receiving traffic. Requests were fine until the busy one retired for its periodic restart, and then the path belonged to the wrong owner until the next deploy.
The lesson was not "add another check", it was know what the teardown actually waits for. That second one is the hard part to test by accident, and it is easy to test on purpose with a small script: start the service, send SIGTERM to the parent, and look at how long the workers took to finish. Running it was the step I had skipped at work, and the script itself is one of the notes I keep.
The three lines we actually monitor
Is a server still listening on the path we think? The probe starts uvicorn --uds <path>, waits until the path is a socket, sends SIGTERM to the parent, and prints the exit code, time to exit, and whether the path was left behind. Exit code 3 is uvicorn's STARTUP_FAILURE, which is what --uds and --fd return when something else already holds the socket. That alone turned the "two processes, one path" incident into a 3 a.m. page that is clear in one line.
Did shutdown finish or did it time out? Compare the elapsed teardown with your rollout's grace period. If teardown equals the grace period almost exactly, your shutdown hook is not finishing; it is being cut. Log the number on every deploy, not only on failures.
Who holds the path afterwards? lsof -U | grep app.sock in the container, before and after. More than one PID means a foreign socket exists, and the next start will adopt whichever one is left.
python probe.py exit=0 teardown=1.84s path_left=False Things I assumed that turned out wrong
- A port that answers is not readiness.
-
curlagainst the service as the health check was measuring the edge, not the worker. - SIGTERM means the same thing to the parent process and to its workers. Half the time it does not, and the difference is not in the docs you first read.
The runbook line now says "run the probe, paste the output in the deploy ticket". The cost is under a minute per service. If your team also runs a few ASGI services behind long-lived sockets, this is a cheap first step. What else do you check after a rolling restart that your load balancer does not see?
