go runtime_error ai_generated true

fatal error: all goroutines are asleep - deadlock! (mutex locked)

ID: go/deadlock-on-mutex

Also available as: JSON · Markdown · 中文
80%Fix Rate
87%Confidence
0Evidence
2024-07-12First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.21 active

Root Cause

一个goroutine持有互斥锁但未释放,其他goroutine等待锁,导致死锁。

generic

中文

一个goroutine持有互斥锁但未释放,其他goroutine等待锁,导致死锁。

Workarounds

  1. 95% success
    mu.Lock(); defer mu.Unlock(); /* ... */
  2. 80% success
    mu.RLock(); defer mu.RUnlock(); /* 读操作 */

Dead Ends

Common approaches that don't work:

  1. 90% fail

    同一goroutine重复锁定同一互斥锁会导致死锁(非重入锁)。

  2. 80% fail

    锁未释放,其他goroutine永远等待。