go
runtime_error
ai_generated
true
fatal error: 所有 goroutine 都处于休眠状态 - 死锁!(WaitGroup 被复制)
fatal error: all goroutines are asleep - deadlock! (WaitGroup copied)
ID: go/waitgroup-passed-by-value
80%修复率
88%置信度
0证据数
2024-08-02首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.14+ | active | — | — | — |
根因分析
sync.WaitGroup 按值传递给函数,导致 Add/Done 作用于副本,原对象的 Wait() 永远无法解除阻塞。
English
A sync.WaitGroup is passed by value to a function, so Add/Done operate on a copy and Wait() on the original never unblocks.
解决方案
-
95% 成功率
func worker(wg *sync.WaitGroup) { defer wg.Done() // ... } -
92% 成功率
type Pool struct { wg sync.WaitGroup } func (p *Pool) Run() { p.wg.Add(1); go func(){ defer p.wg.Done() }() }
无效尝试
常见但无效的做法:
-
80% 失败
The copy bug remains; the timeout just papers over the deadlock without fixing counter propagation.
-
85% 失败
The counters are in different copies; adding to the original still does not match the copy's Done calls.