Leak Detection and Cancellation
Ensuring goroutines exit and preventing leaks
What is a goroutine leak?
A goroutine leak occurs when a goroutine starts but never terminates. Leaked goroutines accumulate over time, consuming stack memory and CPU until the process is killed.
Common leak: blocked channel receive
A goroutine waiting on a channel receive that never gets a value blocks forever:
go func() {
v := <-ch // leaks if no sender and ch is never closed
use(v)
}()All lessons in this course
- Pipeline and Stage Patterns
- errgroup for Concurrent Error Handling
- Semaphore Pattern
- Leak Detection and Cancellation