go
runtime_error
ai_generated
true
fatal error: all goroutines are asleep - deadlock! (mutex held by goroutine 1)
ID: go/deadlock-mutex-hold
80%Fix Rate
88%Confidence
0Evidence
2024-07-18First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.0 | active | — | — | — |
| 1.23 | active | — | — | — |
Root Cause
A goroutine holds a mutex and waits for another goroutine that also needs the same mutex, causing a deadlock.
generic中文
一个goroutine持有互斥锁并等待另一个也需要该锁的goroutine,导致死锁。
Workarounds
-
85% success
Avoid holding mutexes while waiting for other resources. Use lock ordering or try-lock patterns.
-
80% success
Use context.WithTimeout to break deadlocks by aborting the operation.
Dead Ends
Common approaches that don't work:
-
90% fail
Sleep does not resolve the deadlock; the other goroutine is also blocked.
-
80% fail
The deadlock is due to mutex, not channel; buffering does not help.
-
70% fail
This introduces data races and may corrupt data.