Go: fatal error: all goroutines are asleep - deadlock!
Every goroutine is blocked waiting (on a channel, mutex or WaitGroup), so the program can never continue.
Seen on:
Go
Meaning
Classic causes: sending on an unbuffered channel with no receiver, ranging over a channel that’s never closed, WaitGroup.Wait with Add counts that never reach zero, or locking a mutex twice.
Common causes
- Send on unbuffered channel without a receiver goroutine
- range over a channel never closed
- wg.Add/Done mismatch
- Mutex locked twice in the same goroutine
⚡ Quick fix
- Start the receiver before sending or use a buffered channel
- close() channels when producers finish
- Match every Add with Done (defer wg.Done())
Detailed fix by platform
Go
- go
ch := make(chan int) go func() { defer close(ch) for i := 0; i < 3; i++ { ch <- i } }() for v := range ch { fmt.Println(v) }
How to diagnose
- Trace — goroutine states (chan send, chan receive, semacquire)
- Channels — Who closes them?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Other ways to find it
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 7 Oct 2026