# error: context 已取消（goroutine worker 返回）

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

## 根因

父 context 被取消（超时、手动 cancel 或 HTTP 客户端断开），worker goroutine 观察到 ctx.Err() == context.Canceled。

## 版本兼容性

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

## 解决方案

1. **** (92% 成功率)
   ```
   Treat context.Canceled as expected and return without error at shutdown:

if errors.Is(err, context.Canceled) {
    return nil
}
   ```
2. **** (90% 成功率)
   ```
   Propagate the context through all calls and check ctx.Err() at loop boundaries.
   ```

## 无效尝试

- **** — The context remains canceled; retries fail immediately and waste resources. (90% 失败率)
- **** — Leaks the goroutine past shutdown and defeats the purpose of cancellation. (85% 失败率)
