ELLED
grpc
cancellation_error
ai_generated
true
grpc._channel._InactiveRpcError: StatusCode.CANCELLED: Context cancelled
ID: grpc/cancelled-context
85%Fix Rate
88%Confidence
3Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1 | active | — | — | — |
Root Cause
RPC was cancelled by the client. Parent context cancelled, user navigated away, or explicit cancellation.
genericWorkarounds
-
92% success Handle cancellation gracefully on the server side
Check context.is_active() in long-running handlers; abort work early when cancelled to free resources
Sources: https://grpc.io/docs/guides/
-
85% success Distinguish intentional vs. unintentional cancellation on client
Track whether cancellation came from user action (no retry) or parent context (possible retry)
-
82% success Use context.add_callback() to clean up resources on cancellation
context.add_callback(cleanup_fn) # Python server; runs when RPC is cancelled
Dead Ends
Common approaches that don't work:
-
Retry cancelled RPCs unconditionally on the client side
78% fail
If the client explicitly cancelled (e.g., user action), retrying wastes resources and may cause duplicate side effects.
-
Ignore cancellation errors in the server handler
80% fail
Ignoring cancellation means the server continues expensive work that nobody will read. Always check context.is_active().