Senior · Network services
Graceful shutdown and probes
What is the correct shutdown order for a Go service?
Try explaining this aloud before opening the answer. State your assumptions and trace a boundary case.
Reveal a strong answer
Stop accepting new work and become unready, then allow a bounded drain of in-flight requests or jobs. Call Server.Shutdown with a deadline; force remaining cleanup only when that budget expires.
Keep databases, transports and result sinks alive until their users finish. Cancellation signals stop but does not join; explicitly wait for owned goroutines and stop periodic work.
Coordinate the process budget with the orchestrator's termination grace period and traffic propagation. Readiness controls traffic eligibility; liveness determines restart behavior. A failing shared dependency should not automatically trigger a restart storm.
Common trap
Closing the database first makes otherwise healthy in-flight requests fail during deployment.
Try it
A container receives SIGTERM with30 seconds of grace. Reserve a drain and cleanup budget.
Worked solution
Transition readiness immediately, initiate a bounded drain shorter than the full30 seconds, wait for owned workers, then close shared clients. Leave headroom for signal delivery and infrastructure lag; measure a rolling deployment under live traffic.
Change the constraint
What happens to hijacked connections or long-lived streams during Shutdown?
How did you do?
Self-assessment, not a compiler pass or interview score. Explain the reasoning unaided before marking understood.
Not marked. Progress stays on this browser, separate from course completion.
Primary references
Checked 2026-10-20. Use documentation for your pinned runtime, driver and tool version.