# UNAVAILABLE: grpc: 流期间连接关闭: 收到对端的 GOAWAY

- **ID:** `grpc/connection-close-during-stream`
- **领域:** grpc
- **类别:** network_error
- **错误码:** `EGOAWAY`
- **验证级别:** ai_generated
- **修复率:** 70%

## 根因

对端发送了 HTTP/2 GOAWAY 帧，表示正在关闭或重新加载，导致所有活跃流以不可用状态终止。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| gRPC v1.59.0 | active | — | — |
| gRPC v1.62.0 | active | — | — |
| gRPC v1.65.0 | active | — | — |

## 解决方案

1. ```
   Implement client-side retry with exponential backoff and jitter: `from grpc import exponential_backoff; for attempt in range(3): try: response = stub.Call(request); break except grpc.RpcError as e: if e.code() == grpc.StatusCode.UNAVAILABLE: time.sleep(backoff(attempt))`
   ```
2. ```
   Configure the server to drain connections gracefully before shutdown by setting a GOAWAY grace period: `server.graceful_shutdown(timeout=30)`
   ```
3. ```
   Use a load balancer or proxy that can redirect traffic to healthy backends during server restarts.
   ```

## 无效尝试

- **Increasing the client's retry count to 10 or more.** — If the server is permanently down, retries will all fail; retries only help with transient conditions. (60% 失败率)
- **Setting the environment variable GRPC_GOAWAY_MIN_PING_INTERVAL to a very low value.** — This controls ping frequency, not GOAWAY handling; it may trigger additional GOAWAYs due to excessive pings. (90% 失败率)
- **Switching to a different port on the same server.** — GOAWAY is sent for the entire server, not a single port; all ports are affected during shutdown. (95% 失败率)
