# rpc 错误：code = Unavailable，desc = 传输正在关闭

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

## 根因

底层 HTTP/2 传输在 RPC 中途被拆除（服务端重启、空闲超时，或负载均衡器发送 GOAWAY 帧）。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| google.golang.org/grpc 1.55+ | active | — | — |

## 解决方案

1. **** (92% 成功率)
   ```
   Enable client-side retry policy via service config:
conn, _ := grpc.NewClient(addr,
  grpc.WithDefaultServiceConfig(`{"methodConfig":[{"name":[{}],"retryPolicy":{"maxAttempts":5,"initialBackoff":"0.1s","maxBackoff":"1s","backoffMultiplier":2,"retryableStatusCodes":["UNAVAILABLE"]}}]}`))
   ```
2. **** (88% 成功率)
   ```
   Tune keepalive to detect dead transports faster:
grpc.WithKeepaliveParams(keepalive.ClientParameters{Time: 30*time.Second, Timeout: 10*time.Second, PermitWithoutStream: true})
   ```

## 无效尝试

- **** — WithBlock only affects dial; the in-flight RPC still fails with Unavailable. (85% 失败率)
- **** — Keepalive is what detects dead transports; disabling it hides the symptom but leaves zombie connections. (70% 失败率)
