go
runtime_error
ai_generated
true
致命错误:所有 goroutine 都处于休眠状态 - 死锁!
fatal error: all goroutines are asleep - deadlock!
ID: go/channel-deadlock-no-receiver
80%修复率
90%置信度
0证据数
2024-02-11首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.18 | active | — | — | — |
| 1.21 | active | — | — | — |
| 1.22 | active | — | — | — |
根因分析
向无缓冲 channel 发送数据但没有并发的接收方,导致唯一的 goroutine 阻塞,没有任何可运行的 goroutine,从而触发运行时死锁检测。
English
Sending to an unbuffered channel with no concurrent receiver blocks the only goroutine, leaving no runnable goroutines and triggering the runtime deadlock detector.
解决方案
-
95% 成功率
ch := make(chan int) go func() { fmt.Println(<-ch) }() ch <- 42 -
90% 成功率
ch := make(chan int, 1) ch <- 42 // does not block fmt.Println(<-ch)
无效尝试
常见但无效的做法:
-
70% 失败
Still no receiver ever reads, the spawned goroutine blocks forever and the main goroutine exits or deadlocks elsewhere.
-
85% 失败
Sleep does not create a receiver; if no goroutine reads, the send still blocks permanently.