go runtime_error ai_generated true

rpc error: code = Unavailable desc = grpc: the server has been stopped

ID: go/grpc-server-stopped

Also available as: JSON · Markdown · 中文
80%Fix Rate
87%Confidence
0Evidence
2024-07-02First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
google.golang.org/grpc 1.50+ active — — —

Root Cause

A call was made against a grpc.Server after GracefulStop()/Stop() completed, or before Serve() started.

generic

中文

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

Workarounds

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

Dead Ends

Common approaches that don't work:

  1. 95% fail

    grpc.Server cannot be restarted after Stop; you must construct a new one.

  2. 80% fail

    Hides a lifecycle bug where the server is being used after shutdown.