# UNAVAILABLE: grpc: 连接错误: 连接被对端重置

- **ID:** `grpc/grpc-connection-reset-by-peer`
- **领域:** grpc
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 76%

## 根因

TCP 连接被远程对端重置，原因可能是崩溃、超时或防火墙干扰。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| gRPC v1.42.0 | active | — | — |
| gRPC v1.55.0 | active | — | — |
| gRPC v1.61.0 | active | — | — |

## 解决方案

1. ```
   Configure the server to handle graceful shutdown and increase idle timeout. Example in Go: server := grpc.NewServer(grpc.KeepaliveParams(keepalive.ServerParameters{MaxConnectionIdle: 5 * time.Minute}))
   ```
2. ```
   Use a connection pool with retry logic. In Python, use grpc.aio with automatic reconnection: channel = grpc.aio.insecure_channel('localhost:50051'); await channel.channel_ready()
   ```
3. ```
   Check firewall or load balancer settings for idle connection timeouts. Increase TCP keepalive settings on both client and server (e.g., net.ipv4.tcp_keepalive_time=600).
   ```

## 无效尝试

- **** — Connection reset is not a timeout issue; longer timeouts won't prevent the peer from resetting the connection. (80% 失败率)
- **** — TLS is not the cause; disabling it reduces security without fixing the reset. (70% 失败率)
- **** — The server or network issue persists; client restart doesn't address the root cause. (85% 失败率)
