go
runtime_error
ai_generated
true
致命错误:所有goroutine都处于睡眠状态 - 死锁!(sync.Mutex锁顺序)
fatal error: all goroutines are asleep - deadlock! (sync.Mutex lock ordering)
ID: go/goroutine-mutex-lock-deadlock
80%修复率
86%置信度
0证据数
2024-09-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.18 | active | — | — | — |
| 1.19 | active | — | — | — |
| 1.20 | active | — | — | — |
| 1.21 | active | — | — | — |
| 1.22 | active | — | — | — |
根因分析
两个或多个goroutine持有互斥锁并等待对方释放,形成循环依赖。
English
Two or more goroutines hold mutexes and wait for each other to release, creating a circular dependency.
解决方案
-
95% 成功率 Always acquire locks in a consistent global order
// Lock mu1 then mu2; goroutine1: mu1.Lock(); mu2.Lock(); goroutine2: mu1.Lock(); mu2.Lock()
-
80% 成功率 Use try-lock pattern with channels
select { case <-mu: default: // avoid deadlock }
无效尝试
常见但无效的做法:
-
Using sync.RWMutex instead of Mutex
90% 失败
Does not fix lock ordering issue.
-
Adding sleep to break deadlock
95% 失败
Sleep does not resolve logical cycle.