all goroutines are asleep - deadlock 🐹 Go

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

  1. Start the receiver before sending or use a buffered channel
  2. close() channels when producers finish
  3. Match every Add with Done (defer wg.Done())

Detailed fix by platform

Go

  1. 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

  1. Trace — goroutine states (chan send, chan receive, semacquire)
  2. 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:

🧠 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.