go
runtime_error
ai_generated
true
fatal error: all goroutines are asleep - deadlock! (sync.Mutex.Lock on already-held lock)
ID: go/mutex-double-lock-self-deadlock
80%Fix Rate
87%Confidence
0Evidence
2024-04-17First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.18 | active | — | — | — |
| 1.22 | active | — | — | — |
Root Cause
The same goroutine calls Lock() twice on a non-reentrant sync.Mutex, or a locked method calls another method that locks the same mutex.
generic中文
同一个 goroutine 对不可重入的 sync.Mutex 调用两次 Lock(),或已加锁的方法调用另一个锁定同一互斥锁的方法。
Workarounds
-
95% success
Split into exported methods that lock and unexported helpers that assume the lock is held; never call Lock inside a locked section
-
85% success
Use defer mu.Unlock() consistently and audit call chains for re-entrancy
Dead Ends
Common approaches that don't work:
-
90% fail
The goroutine itself holds the lock; retry never succeeds
-
75% fail
RLock while holding RLock is allowed but Lock after RLock still deadlocks