# rpc 错误：代码 = Unknown 描述 = 意外的 EOF

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

## 根因

gRPC 流被突然关闭，可能是由于网络问题或服务器崩溃，客户端收到 EOF 而没有正确的状态码。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.5 | active | — | — |

## 解决方案

1. **Use a new connection for retries** (85% 成功率)
   ```
   conn, _ := grpc.NewClient("localhost:50051", grpc.WithTransportCredentials(insecure.NewCredentials()))
defer conn.Close()
   ```
2. **Enable keepalive and connection recovery** (75% 成功率)
   ```
   grpc.WithKeepaliveParams(keepalive.ClientParameters{Time: 10 * time.Second, Timeout: 3 * time.Second, PermitWithoutStream: true})
   ```

## 无效尝试

- **Retry the RPC immediately with the same connection** — The connection is likely broken, so retrying on the same connection will fail again. (80% 失败率)
- **Ignore the error and assume the response is empty** — The RPC did not complete successfully, so the response is invalid. (100% 失败率)
