go runtime_error ai_generated true

fatal error: all goroutines are asleep - deadlock!

ID: go/deadlock-all-goroutines-asleep

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.18 active
1.20 active
1.22 active

Root Cause

The runtime detects that no goroutine can ever make progress — every goroutine is blocked on a channel send/receive, mutex, or WaitGroup with no possible unblocking.

generic

中文

运行时检测到没有任何 goroutine 能继续推进——所有 goroutine 都阻塞在 channel 收发、互斥锁或 WaitGroup 上,且永远无法被唤醒。

Workarounds

  1. 90% success
    ch := make(chan int, 1)
    go func(){ ch <- 1 }()
    v := <-ch
  2. 87% success
    select {
    case v := <-ch:
        _ = v
    case <-time.After(time.Second):
        return
    }

Dead Ends

Common approaches that don't work:

  1. 90% fail

    The blocking condition is logical, not timing-based; sleeping just delays the fatal error.

  2. 85% fail

    Deadlock is independent of parallelism; more OS threads do not create a receiver.