# rpc 错误：代码 = Canceled 描述 = grpc：客户端连接正在关闭

- **ID:** `go/grpc-canceled-context`
- **领域:** go
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

客户端 gRPC 连接在请求进行中被关闭（例如通过 conn.Close()），导致 RPC 被取消。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.x | active | — | — |

## 解决方案

1. **** (85% 成功率)
   ```
   if conn == nil { conn, _ = grpc.Dial(address, grpc.WithInsecure()) }; resp, err := client.Call(ctx, ...)
   ```
2. **** (80% 成功率)
   ```
   Implement a pool that returns a new connection if the old one is closed.
   ```

## 无效尝试

- **** — The connection is closed; subsequent requests will also fail. (95% 失败率)
- **** — The connection is already closed; you need a new connection. (90% 失败率)
