go
network_error
ai_generated
true
错误: 上下文已取消
error: context canceled
ID: go/context-canceled-propagation
80%修复率
88%置信度
0证据数
2024-03-30首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.7+ | active | — | — | — |
根因分析
父上下文被取消(或超时),而子操作仍在进行。错误来自 HTTP 客户端、数据库查询或检查 ctx.Err() 的自定义代码。
English
A parent context was canceled (or timed out) while a child operation was in progress. The error surfaces from HTTP clients, DB queries, or custom code checking ctx.Err().
解决方案
-
92% 成功率
if err := ctx.Err(); err != nil { return err } -
85% 成功率
retryCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() resp, err := client.Do(req.WithContext(retryCtx))
无效尝试
常见但无效的做法:
-
95% 失败
The context remains canceled; retries fail instantly without making a request.
-
80% 失败
Ignores the caller's shutdown intent; leaks work after the request is abandoned.