# rpc 错误：code = Unavailable，desc = grpc：服务端已停止

- **ID:** `go/grpc-server-stopped`
- **领域:** go
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在 grpc.Server 的 GracefulStop()/Stop() 完成后，或在 Serve() 启动前发起了调用。

## 版本兼容性

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

## 解决方案

1. **** (92% 成功率)
   ```
   Order shutdown correctly:
// on SIGTERM
srv.GracefulStop() // stops accepting, drains in-flight
lis.Close()
// construct a fresh server on restart
   ```
2. **** (88% 成功率)
   ```
   Guard server lifecycle with sync.Once and a ready channel; only issue calls after Serve() has started (use a health check).
   ```

## 无效尝试

- **** — grpc.Server cannot be restarted after Stop; you must construct a new one. (95% 失败率)
- **** — Hides a lifecycle bug where the server is being used after shutdown. (80% 失败率)
