go
runtime_error
ai_generated
true
fatal error: sync: Unlock of unlocked mutex
ID: go/goroutine-mutex-not-unlocked
80%Fix Rate
86%Confidence
0Evidence
2024-07-22First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.0 | active | — | — | — |
| 1.21 | active | — | — | — |
Root Cause
Calling Unlock on a mutex that wasn't locked by the same goroutine, often due to missing Lock or double Unlock.
generic中文
对未被同一协程锁定的互斥锁调用Unlock,通常由于缺少Lock或重复Unlock。
Workarounds
-
99% success Use defer to ensure Unlock is called exactly once after Lock
mu.Lock() defer mu.Unlock() // critical section
-
90% success Use sync.Mutex with proper pairing in all code paths
mu.Lock() if condition { mu.Unlock() return } mu.Unlock()
Dead Ends
Common approaches that don't work:
-
Using recover() to catch panic
100% fail
Panic is fatal and cannot be recovered in Go runtime; program crashes.
-
Adding more Unlock calls to match Lock
90% fail
Double unlock causes panic; correct pairing is required.