go
network_error
ai_generated
true
error: context canceled
ID: go/context-canceled-propagation
80%Fix Rate
88%Confidence
0Evidence
2024-03-30First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.7+ | active | — | — | — |
Root Cause
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().
generic中文
父上下文被取消(或超时),而子操作仍在进行。错误来自 HTTP 客户端、数据库查询或检查 ctx.Err() 的自定义代码。
Workarounds
-
92% success
if err := ctx.Err(); err != nil { return err } -
85% success
retryCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() resp, err := client.Do(req.WithContext(retryCtx))
Dead Ends
Common approaches that don't work:
-
95% fail
The context remains canceled; retries fail instantly without making a request.
-
80% fail
Ignores the caller's shutdown intent; leaks work after the request is abandoned.