Stage 1 · Code
Capstone — Ship a Real Tool
Graceful Shutdown
Handle OS signals to shut down cleanly — finish in-flight requests, flush buffers, and release resources before exiting.
OS Signals
When you press Ctrl+C or a container stops, the OS sends SIGINT or SIGTERM. If your program ignores these signals and simply exits, in-flight work is lost. Graceful shutdown gives work time to complete.
Context Cancellation for Shutdown
Create a root context that is cancelled on signal receipt. Pass it to all goroutines. When the context is done, every goroutine cleans up and exits.
HTTP Server Shutdown
http.Server.Shutdown stops accepting new connections and waits for in-flight requests to complete, up to the given context deadline.
Worker Cleanup
Background workers should flush their buffers and release connections when the context is cancelled. Use a sync.WaitGroup to wait for all workers before the process exits.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.