# rpc error: code = Canceled desc = context canceled

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

## Root Cause

The client canceled the context (e.g., HTTP request aborted, timeout on parent ctx, or explicit cancel()) before the RPC completed.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| google.golang.org/grpc v1.50+ | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   resp, err := client.Get(ctx, req)
if err != nil {
    if errors.Is(ctx.Err(), context.Canceled) {
        log.Printf("caller canceled: %v", ctx.Err())
        return nil, err
    }
    if status.Code(err) == codes.Canceled {
        return nil, status.Error(codes.Canceled, "server canceled RPC")
    }
    return nil, err
}
   ```
2. **** (88% success)
   ```
   for {
    select {
    case <-ctx.Done():
        return nil, status.FromContextError(ctx.Err()).Err()
    default:
        // do work
    }
}
   ```

## Dead Ends

- **** — If the caller canceled, the retry will also be canceled immediately — wasted work. (90% fail)
- **** — Loses parent deadline/cancellation propagation; goroutines leak on client disconnect. (85% fail)
