go
runtime_error
ai_generated
true
fatal error: all goroutines are asleep - deadlock! (sync.Mutex lock ordering)
ID: go/goroutine-mutex-lock-deadlock
80%Fix Rate
86%Confidence
0Evidence
2024-09-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.18 | active | — | — | — |
| 1.19 | active | — | — | — |
| 1.20 | active | — | — | — |
| 1.21 | active | — | — | — |
| 1.22 | active | — | — | — |
Root Cause
Two or more goroutines hold mutexes and wait for each other to release, creating a circular dependency.
generic中文
两个或多个goroutine持有互斥锁并等待对方释放,形成循环依赖。
Workarounds
-
95% success Always acquire locks in a consistent global order
// Lock mu1 then mu2; goroutine1: mu1.Lock(); mu2.Lock(); goroutine2: mu1.Lock(); mu2.Lock()
-
80% success Use try-lock pattern with channels
select { case <-mu: default: // avoid deadlock }
Dead Ends
Common approaches that don't work:
-
Using sync.RWMutex instead of Mutex
90% fail
Does not fix lock ordering issue.
-
Adding sleep to break deadlock
95% fail
Sleep does not resolve logical cycle.