# 错误: 上下文已取消

- **ID:** `go/context-canceled-propagation`
- **领域:** go
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

父上下文被取消（或超时），而子操作仍在进行。错误来自 HTTP 客户端、数据库查询或检查 ctx.Err() 的自定义代码。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.7+ | active | — | — |

## 解决方案

1. **** (92% 成功率)
   ```
   if err := ctx.Err(); err != nil {
    return err
}
   ```
2. **** (85% 成功率)
   ```
   retryCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
resp, err := client.Do(req.WithContext(retryCtx))
   ```

## 无效尝试

- **** — The context remains canceled; retries fail instantly without making a request. (95% 失败率)
- **** — Ignores the caller's shutdown intent; leaks work after the request is abandoned. (80% 失败率)
