go runtime_error ai_generated true

fatal error: 所有 goroutine 都休眠了 - 死锁!

fatal error: all goroutines are asleep - deadlock!

ID: go/deadlock-all-goroutines-asleep

其他格式: JSON · Markdown 中文 · English
80%修复率
90%置信度
0证据数
2024-01-20首次发现

版本兼容性

版本状态引入弃用备注
1.18 active
1.20 active
1.22 active

根因分析

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

English

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

解决方案

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

无效尝试

常见但无效的做法:

  1. 90% 失败

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

  2. 85% 失败

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