go runtime_error ai_generated true

致命错误:所有 goroutine 都已休眠 - 死锁!(sync.Once.Do 递归调用自身)

fatal error: all goroutines are asleep - deadlock! (sync.Once.Do calling itself)

ID: go/sync-once-deadlock-recursive

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

版本兼容性

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

根因分析

sync.Once.Do 的函数再次(直接或间接)调用同一个 Once.Do,永久阻塞在自己的互斥锁上。

English

A sync.Once.Do function calls the same Once.Do again (directly or indirectly), blocking on its own mutex forever.

generic

解决方案

  1. 95% 成功率
    Ensure the function passed to Do never calls the same Once; extract shared init into a separate helper
  2. 88% 成功率
    Use sync.OnceFunc/OnceValue (Go 1.21+) and keep init logic non-reentrant

无效尝试

常见但无效的做法:

  1. 90% 失败

    Once holds an internal mutex with no timeout support; deadlock persists

  2. 80% 失败

    Loses thread-safety; introduces data races