How does Go's deadlock detection work, and what conditions cause a 'fatal error: all goroutines are asleep' panic?
Last updated
The runtime panics with
fatal error: all goroutines are asleep - deadlock!when zero goroutines are runnable, meaning nothing can ever wake them.Common triggers: sending/receiving on an unbuffered channel with no partner, receiving from a channel never written or closed, or all goroutines stuck on
WaitGroup.Wait()or an unreleased mutex.It only detects a total global stall. Partial deadlocks, or hangs while a timer or network poller keeps something alive, go undetected.