# 恐慌：上下文已取消（在 goroutine 中）

- **ID:** `go/context-cancel-not-propagated`
- **领域:** go
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

上下文被取消，但 goroutine 未检查上下文并尝试使用它，导致恐慌或错误。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   Check ctx.Err() before and after operations, and return early if canceled.
   ```
2. **** (95% 成功率)
   ```
   Pass ctx to all functions and use select with ctx.Done() to handle cancellation.
   ```

## 无效尝试

- **** — May lead to resource leaks or incorrect results; cancellation should be respected. (80% 失败率)
- **** — Loses cancellation ability; may cause indefinite blocking. (60% 失败率)
