# rpc error: code = Canceled desc = grpc: the client connection is closing

- **ID:** `go/grpc-stream-interrupted-client-cancel`
- **Domain:** go
- **Category:** network_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The gRPC client cancelled the context, causing the streaming RPC to terminate prematurely.

## Version Compatibility

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

## Workarounds

1. **Handle context cancellation gracefully and restart stream.** (90% success)
   ```
   for {
    stream, err := client.StreamRPC(ctx)
    if err != nil { return }
    for {
        msg, err := stream.Recv()
        if errors.Is(err, context.Canceled) { break }
    }
}
   ```
2. **Use a separate context for stream to avoid parent cancellation.** (85% success)
   ```
   streamCtx, cancel := context.WithCancel(context.Background())
defer cancel()
stream, _ := client.StreamRPC(streamCtx)
   ```

## Dead Ends

- **Ignore the cancellation and retry the same stream.** — Stream is closed; must create a new stream. (95% fail)
- **Increase context timeout to avoid cancellation.** — Cancellation may be intentional (e.g., user abort). (70% fail)
