Graceful Shutdown
Stop workers cleanly.
Why Graceful Shutdown
Long-running goroutines must be told when to stop. Graceful shutdown lets workers finish current work, release resources, and exit without leaking or losing data.
- No goroutine leaks
- No half-finished writes
- Clean process exit
The done Channel Pattern
A classic approach is a done channel. Closing it broadcasts a stop signal to all goroutines listening on it, because a closed channel returns immediately on receive.
done := make(chan struct{})
// ... later
close(done)All lessons in this course
- Worker Pool Pattern
- Fan-Out Fan-In
- Pipeline Stages
- Graceful Shutdown