Graceful shutdown
Stopping a process without losing work: stop taking new work, drain what is in flight, stop background loops, then close clients and pools, all under a deadline shorter than the platform's grace period.
Minimal example
shutdownCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_ = srv.Shutdown(shutdownCtx)Learn this concept
Lesson 3.18 · Signal-driven shutdownUsed in exercises
Exercise 3.19 · API and notifier shutdown Exercise 6.4 · API and worker metricsPrerequisite conceptsGoroutine lifecycle
RelatedOS signal