go
runtime_error
ai_generated
true
panic: context canceled (in goroutine)
ID: go/context-cancel-not-propagated
80%Fix Rate
85%Confidence
0Evidence
2024-11-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.20 | active | — | — | — |
| 1.22 | active | — | — | — |
Root Cause
A context is canceled, but a goroutine doesn't check the context and tries to use it, causing a panic or error.
generic中文
上下文被取消,但 goroutine 未检查上下文并尝试使用它,导致恐慌或错误。
Workarounds
-
90% success
Check ctx.Err() before and after operations, and return early if canceled.
-
95% success
Pass ctx to all functions and use select with ctx.Done() to handle cancellation.
Dead Ends
Common approaches that don't work:
-
80% fail
May lead to resource leaks or incorrect results; cancellation should be respected.
-
60% fail
Loses cancellation ability; may cause indefinite blocking.