go
runtime_error
ai_generated
true
rpc 错误:code = Unavailable,desc = grpc:服务端已停止
rpc error: code = Unavailable desc = grpc: the server has been stopped
ID: go/grpc-server-stopped
80%修复率
87%置信度
0证据数
2024-07-02首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| google.golang.org/grpc 1.50+ | active | — | — | — |
根因分析
在 grpc.Server 的 GracefulStop()/Stop() 完成后,或在 Serve() 启动前发起了调用。
English
A call was made against a grpc.Server after GracefulStop()/Stop() completed, or before Serve() started.
解决方案
-
92% 成功率
Order shutdown correctly: // on SIGTERM srv.GracefulStop() // stops accepting, drains in-flight lis.Close() // construct a fresh server on restart
-
88% 成功率
Guard server lifecycle with sync.Once and a ready channel; only issue calls after Serve() has started (use a health check).
无效尝试
常见但无效的做法:
-
95% 失败
grpc.Server cannot be restarted after Stop; you must construct a new one.
-
80% 失败
Hides a lifecycle bug where the server is being used after shutdown.