go runtime_error ai_generated true

fatal error: 所有 goroutine 都处于休眠状态 - 死锁!

fatal error: all goroutines are asleep - deadlock!

ID: go/all-goroutines-asleep-deadlock

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

版本兼容性

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

根因分析

主 goroutine 阻塞在没有任何其他 goroutine 能满足的 channel 接收/发送上;运行时检测到完全无活动后中止。

English

Main goroutine blocks on a channel receive/send that no other goroutine can satisfy; runtime detects total inactivity and aborts.

generic

解决方案

  1. 92% 成功率
    ch := make(chan int, 1)
    ch <- 42 // non-blocking with buffer
    v := <-ch
    _ = v
  2. 90% 成功率
    select {
    case v := <-ch:
        _ = v
    case <-time.After(2 * time.Second):
        return errors.New("timeout waiting for value")
    }

无效尝试

常见但无效的做法:

  1. 95% 失败

    Sleep does not create a sender; deadlock still occurs and adds nondeterminism.

  2. 99% 失败

    Deadlock is a fatal runtime error, not a panic; recover never runs.