go
runtime_error
ai_generated
true
致命错误:所有goroutine都处于休眠状态 - 死锁!(互斥锁由goroutine 1持有)
fatal error: all goroutines are asleep - deadlock! (mutex held by goroutine 1)
ID: go/deadlock-mutex-hold
80%修复率
88%置信度
0证据数
2024-07-18首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.0 | active | — | — | — |
| 1.23 | active | — | — | — |
根因分析
一个goroutine持有互斥锁并等待另一个也需要该锁的goroutine,导致死锁。
English
A goroutine holds a mutex and waits for another goroutine that also needs the same mutex, causing a deadlock.
解决方案
-
85% 成功率
Avoid holding mutexes while waiting for other resources. Use lock ordering or try-lock patterns.
-
80% 成功率
Use context.WithTimeout to break deadlocks by aborting the operation.
无效尝试
常见但无效的做法:
-
90% 失败
Sleep does not resolve the deadlock; the other goroutine is also blocked.
-
80% 失败
The deadlock is due to mutex, not channel; buffering does not help.
-
70% 失败
This introduces data races and may corrupt data.