go
runtime_error
ai_generated
true
fatal error: all goroutines are asleep - deadlock! (mutex lock ordering)
ID: go/deadlock-two-mutexes
80%Fix Rate
88%Confidence
0Evidence
2024-11-12First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.0+ | active | — | — | — |
Root Cause
Two goroutines acquire mutexes A and B in opposite orders, each waiting for the other's lock.
generic中文
两个 goroutine 以相反顺序获取互斥锁 A 和 B,各自等待对方持有的锁。
Workarounds
-
92% success
// always lock A then B muA.Lock() defer muA.Unlock() muB.Lock() defer muB.Unlock()
-
88% success
var mu sync.Mutex mu.Lock() defer mu.Unlock() // access both A and B
Dead Ends
Common approaches that don't work:
-
70% fail
Busy retry burns CPU and does not guarantee progress; can still livelock.
-
60% fail
Serializes everything, destroying concurrency, and may still deadlock with other lock paths.