go
runtime_error
ai_generated
true
致命错误:所有 goroutine 都处于休眠状态 - 死锁!(goroutine 1 [通道发送])
fatal error: all goroutines are asleep - deadlock! (goroutine 1 [chan send])
ID: go/goroutine-leak-no-receiver
80%修复率
86%置信度
0证据数
2024-04-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.20 | active | — | — | — |
| 1.21 | active | — | — | — |
根因分析
一个 goroutine 在向没有活动接收者的通道发送时卡住,主 goroutine 在等待它,导致死锁。
English
A goroutine is stuck sending to a channel with no active receiver, and the main goroutine is waiting for it, causing a deadlock.
解决方案
-
95% 成功率
ch := make(chan int); go func() { <-ch }(); ch <- 42 -
85% 成功率
ch := make(chan int, 1); ch <- 42
无效尝试
常见但无效的做法:
-
75% 失败
If sender sends more than buffer size, it still blocks without receiver.
-
90% 失败
Sleep doesn't add a receiver; block remains after sleep.