go runtime_error ai_generated true

fatal error: all goroutines are asleep - deadlock! (goroutine 1 [semacquire])

ID: go/goroutine-blocked-on-mutex

Also available as: JSON · Markdown · 中文
80%Fix Rate
86%Confidence
0Evidence
2024-05-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.20 active
1.21 active

Root Cause

A goroutine is blocked trying to acquire a mutex that is already locked by another goroutine that is also blocked, causing a deadlock.

generic

中文

一个 goroutine 在尝试获取一个已被另一个也阻塞的 goroutine 锁定的互斥锁时阻塞,导致死锁。

Workarounds

  1. 95% success
    mu1.Lock(); mu2.Lock(); defer mu1.Unlock(); defer mu2.Unlock()
  2. 85% success
    if mu.TryLock(time.Second) { defer mu.Unlock() } else { handleTimeout() }

Dead Ends

Common approaches that don't work:

  1. 70% fail

    If logic requires same mutex, deadlock persists.

  2. 90% fail

    Sleep doesn't resolve circular wait.