go runtime_error ai_generated true

fatal error: all goroutines are asleep - deadlock! (mutex held by goroutine 1)

ID: go/deadlock-mutex-hold

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
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

  1. 85% success
    Avoid holding mutexes while waiting for other resources. Use lock ordering or try-lock patterns.
  2. 80% success
    Use context.WithTimeout to break deadlocks by aborting the operation.

Dead Ends

Common approaches that don't work:

  1. 90% fail

    Sleep does not resolve the deadlock; the other goroutine is also blocked.

  2. 80% fail

    The deadlock is due to mutex, not channel; buffering does not help.

  3. 70% fail

    This introduces data races and may corrupt data.