go runtime_error ai_generated true

fatal error: all goroutines are asleep - deadlock!

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

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.21 active
1.22 active

Root Cause

All goroutines are blocked waiting on channels or locks with no possibility of progress, typically due to circular dependencies or missing sends/receives.

generic

中文

所有协程都在等待通道或锁,无法继续执行,通常是由于循环依赖或缺少发送/接收操作。

Workarounds

  1. 99% success Ensure each channel send has a corresponding receive in another goroutine
    ch := make(chan int)
    go func() {
        ch <- 1
    }()
    result := <-ch
  2. 85% success Use buffered channels to avoid blocking
    ch := make(chan int, 1)
    ch <- 1
    // no receiver needed immediately

Dead Ends

Common approaches that don't work:

  1. Adding more goroutines to break the deadlock 95% fail

    More goroutines will also block if they follow the same pattern, exacerbating the issue.

  2. Using time.Sleep to wait for conditions 90% fail

    Sleep does not resolve the fundamental blocking; it only delays the deadlock detection.