go runtime_error ai_generated true

fatal error: semacquire: semacquire goroutine 1 [semacquire]: sync.runtime_Semacquire(...)

ID: go/semacquire-deadlock

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

版本兼容性

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

根因分析

某个同步原语(Mutex、WaitGroup、RWMutex)被持有或等待,导致无法推进;运行时报告 semacquire 死锁。

English

A sync primitive (Mutex, WaitGroup, RWMutex) is held or waited on such that no progress is possible; runtime reports semacquire deadlock.

generic

解决方案

  1. 90% 成功率
    // Always lock A then B, never B then A.
    muA.Lock(); muB.Lock(); ...; muB.Unlock(); muA.Unlock()
  2. 80% 成功率
    if !mu.TryLock() {
        return errors.New("lock timeout")
    }
    defer mu.Unlock()

无效尝试

常见但无效的做法:

  1. 85% 失败

    Atomics cannot express compound invariants; logic still deadlocks.

  2. 90% 失败

    Does not resolve lock ordering; can still deadlock.