go
runtime_error
ai_generated
true
fatal error: sync: RUnlock of unlocked RWMutex
ID: go/rwmutex-unlock-of-unlocked
80%Fix Rate
86%Confidence
0Evidence
2024-10-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.18 | active | — | — | — |
| 1.21 | active | — | — | — |
| 1.22 | active | — | — | — |
Root Cause
RUnlock() is called without a matching RLock(), often because the lock was acquired with Lock() but released with RUnlock().
generic中文
在没有对应 RLock() 的情况下调用 RUnlock(),常见于用 Lock() 加锁却用 RUnlock() 解锁的情况。
Workarounds
-
94% success
mu.RLock() defer mu.RUnlock() // read-only section
-
85% success
type RLocked struct{ mu *sync.RWMutex } func (r RLocked) Unlock() { r.mu.RUnlock() }
Dead Ends
Common approaches that don't work:
-
80% fail
Hides the panic but leaves the RWMutex in a corrupted state, causing deadlocks later.
-
55% fail
It removes read concurrency and may mask but not fix the mismatched lock/unlock pairs.