# 致命错误：所有 goroutine 都已休眠 - 死锁！（sync.Once.Do 递归调用自身）

- **ID:** `go/sync-once-deadlock-recursive`
- **领域:** go
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.21 | active | — | — |
| 1.22 | active | — | — |

## 解决方案

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
   ```

## 无效尝试

- **** — Once holds an internal mutex with no timeout support; deadlock persists (90% 失败率)
- **** — Loses thread-safety; introduces data races (80% 失败率)
