go runtime_error ai_generated true

fatal error: all goroutines are asleep - deadlock!

ID: go/deadlock-all-goroutines-asleep-channel

Also available as: JSON · Markdown · 中文
80%Fix Rate
90%Confidence
0Evidence
2024-03-12First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.0+ active — — —

Root Cause

All goroutines are blocked waiting on channel operations (send/receive) or sync primitives, and the runtime detects no goroutine can make progress. Common when an unbuffered channel send has no receiver, or a receive has no sender.

generic

中文

所有 goroutine 都阻塞在 channel 操作或同步原语上,运行时检测到没有任何 goroutine 能继续推进。常见于无缓冲 channel 发送无接收者,或接收无发送者。

Workarounds

  1. 90% success
    ch := make(chan int, 1)
    ch <- 42 // no longer blocks
    // or:
    go func() { ch <- 42 }()
    <-ch
  2. 85% success
    select {
    case ch <- v:
    case <-time.After(time.Second):
    	log.Println("send timeout")
    }

Dead Ends

Common approaches that don't work:

  1. 95% fail

    Sleep does not unblock a channel operation; the deadlock persists and only adds latency. The runtime still detects all goroutines asleep.

  2. 99% fail

    Deadlock is a fatal runtime error, not a panic; recover() cannot intercept it and the program aborts.