# error: context canceled

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

## 根因

上下文被取消（父级取消、超时或客户端断开），而下游操作正在进行。任何感知上下文的调用都会返回此错误。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   if errors.Is(err, context.Canceled) {
    return nil // expected on shutdown
}
   ```
2. **** (88% 成功率)
   ```
   if errors.Is(err, context.DeadlineExceeded) { retry() }
if errors.Is(err, context.Canceled) { return err }
   ```

## 无效尝试

- **** — Retrying with the same canceled context fails instantly in a tight loop; burns CPU and logs. (85% 失败率)
- **** — Removes timeout propagation; leaked requests and shutdown hangs. (80% 失败率)
