go runtime_error ai_generated true

致命错误:所有 goroutine 都处于休眠状态 - 死锁!

fatal error: all goroutines are asleep - deadlock!

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

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

版本兼容性

版本状态引入弃用备注
1.0+ active — — —

根因分析

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

English

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

解决方案

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

无效尝试

常见但无效的做法:

  1. 95% 失败

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

  2. 99% 失败

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