go
runtime_error
ai_generated
true
error: context canceled (goroutine worker returned)
ID: go/context-canceled-during-goroutine
80%Fix Rate
87%Confidence
0Evidence
2024-11-20First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.20 | active | — | — | — |
| 1.21 | active | — | — | — |
| 1.22 | active | — | — | — |
| 1.23 | active | — | — | — |
Root Cause
A parent context was canceled (deadline, manual cancel, or HTTP client disconnect) and the worker goroutine observes ctx.Err() == context.Canceled.
generic中文
父 context 被取消(超时、手动 cancel 或 HTTP 客户端断开),worker goroutine 观察到 ctx.Err() == context.Canceled。
Workarounds
-
92% success
Treat context.Canceled as expected and return without error at shutdown: if errors.Is(err, context.Canceled) { return nil } -
90% success
Propagate the context through all calls and check ctx.Err() at loop boundaries.
Dead Ends
Common approaches that don't work:
-
90% fail
The context remains canceled; retries fail immediately and waste resources.
-
85% fail
Leaks the goroutine past shutdown and defeats the purpose of cancellation.