go
runtime_error
ai_generated
true
致命错误:所有 goroutine 都处于休眠状态 - 死锁!(goroutine 1 [信号量获取])
fatal error: all goroutines are asleep - deadlock! (goroutine 1 [semacquire])
ID: go/goroutine-blocked-on-mutex
80%修复率
86%置信度
0证据数
2024-05-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.20 | active | — | — | — |
| 1.21 | active | — | — | — |
根因分析
一个 goroutine 在尝试获取一个已被另一个也阻塞的 goroutine 锁定的互斥锁时阻塞,导致死锁。
English
A goroutine is blocked trying to acquire a mutex that is already locked by another goroutine that is also blocked, causing a deadlock.
解决方案
-
95% 成功率
mu1.Lock(); mu2.Lock(); defer mu1.Unlock(); defer mu2.Unlock()
-
85% 成功率
if mu.TryLock(time.Second) { defer mu.Unlock() } else { handleTimeout() }
无效尝试
常见但无效的做法:
-
70% 失败
If logic requires same mutex, deadlock persists.
-
90% 失败
Sleep doesn't resolve circular wait.