go
runtime_error
ai_generated
true
致命错误:所有协程都在休眠 - 死锁!(互斥锁被锁定)
fatal error: all goroutines are asleep - deadlock! (mutex locked)
ID: go/deadlock-on-mutex
80%修复率
87%置信度
0证据数
2024-07-12首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.21 | active | — | — | — |
根因分析
一个goroutine持有互斥锁但未释放,其他goroutine等待锁,导致死锁。
English
一个goroutine持有互斥锁但未释放,其他goroutine等待锁,导致死锁。
解决方案
-
95% 成功率
mu.Lock(); defer mu.Unlock(); /* ... */
-
80% 成功率
mu.RLock(); defer mu.RUnlock(); /* 读操作 */
无效尝试
常见但无效的做法:
-
90% 失败
同一goroutine重复锁定同一互斥锁会导致死锁(非重入锁)。
-
80% 失败
锁未释放,其他goroutine永远等待。