go runtime_error ai_generated true

致命错误:所有 goroutine 都已休眠 - 死锁!(对已持有的 sync.Mutex.Lock 再次加锁)

fatal error: all goroutines are asleep - deadlock! (sync.Mutex.Lock on already-held lock)

ID: go/mutex-double-lock-self-deadlock

其他格式: JSON · Markdown 中文 · English
80%修复率
87%置信度
0证据数
2024-04-17首次发现

版本兼容性

版本状态引入弃用备注
1.18 active — — —
1.22 active — — —

根因分析

同一个 goroutine 对不可重入的 sync.Mutex 调用两次 Lock(),或已加锁的方法调用另一个锁定同一互斥锁的方法。

English

The same goroutine calls Lock() twice on a non-reentrant sync.Mutex, or a locked method calls another method that locks the same mutex.

generic

解决方案

  1. 95% 成功率
    Split into exported methods that lock and unexported helpers that assume the lock is held; never call Lock inside a locked section
  2. 85% 成功率
    Use defer mu.Unlock() consistently and audit call chains for re-entrancy

无效尝试

常见但无效的做法:

  1. 90% 失败

    The goroutine itself holds the lock; retry never succeeds

  2. 75% 失败

    RLock while holding RLock is allowed but Lock after RLock still deadlocks