# rpc error: code = Canceled desc = context canceled

- **ID:** `go/grpc-canceled-context-cancelled`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The client cancelled the context before the RPC completed, often due to user action or timeout.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.0 | active | — | — |
| 1.1 | active | — | — |

## Workarounds

1. **Create a new context for each RPC call to avoid using cancelled contexts.** (90% success)
   ```
   ctx := context.Background()
resp, err := client.SomeRPC(ctx, req)
if err != nil {
    if status.Code(err) == codes.Canceled {
        // Create new context and retry if appropriate
        ctx2 := context.Background()
        resp, err = client.SomeRPC(ctx2, req)
    }
}
   ```
2. **Handle cancellation gracefully by checking context errors.** (85% success)
   ```
   select {
case <-ctx.Done():
    return nil, ctx.Err()
default:
}
resp, err := client.SomeRPC(ctx, req)
   ```

## Dead Ends

- **Ignore the cancellation and retry with the same context.** — The cancelled context cannot be reused; a new context is needed. (100% fail)
- **Remove context cancellation logic entirely.** — This can lead to resource leaks and unresponsive applications. (90% fail)
