go
runtime_error
ai_generated
true
fatal error: all goroutines are asleep - deadlock! (mutex locked)
ID: go/deadlock-on-mutex
80%Fix Rate
87%Confidence
0Evidence
2024-07-12First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.21 | active | — | — | — |
Root Cause
一个goroutine持有互斥锁但未释放,其他goroutine等待锁,导致死锁。
generic中文
一个goroutine持有互斥锁但未释放,其他goroutine等待锁,导致死锁。
Workarounds
-
95% success
mu.Lock(); defer mu.Unlock(); /* ... */
-
80% success
mu.RLock(); defer mu.RUnlock(); /* 读操作 */
Dead Ends
Common approaches that don't work:
-
90% fail
同一goroutine重复锁定同一互斥锁会导致死锁(非重入锁)。
-
80% fail
锁未释放,其他goroutine永远等待。