go
system_error
ai_generated
true
rpc error: code = Internal desc = grpc: the server has been stopped
ID: go/grpc-server-stream-closed
80%Fix Rate
87%Confidence
0Evidence
2024-03-28First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| google.golang.org/grpc 1.40+ | active | — | — | — |
Root Cause
A handler attempted to send on a stream after grpc.Server.Stop() or GracefulStop() was called. Common during shutdown when in-flight handlers are not drained.
generic中文
在调用 grpc.Server.Stop() 或 GracefulStop() 后,处理器仍尝试在流上发送。常见于关闭期间未排空进行中的处理器。
Workarounds
-
95% success
Use GracefulStop with a timeout fallback: done := make(chan struct{}) go func() { grpcServer.GracefulStop() close(done) }() select { case <-done: case <-time.After(30 * time.Second): grpcServer.Stop() } -
90% success
Check ctx.Err() before each Send in streaming handlers: if err := stream.Context().Err(); err != nil { return status.FromContextError(err).Err() }
Dead Ends
Common approaches that don't work:
-
80% fail
Restarting does not drain in-flight handlers; the error recurs on the next shutdown.
-
75% fail
Clients receive truncated responses and may retry with stale state.