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

- **ID:** `go/grpc-server-stream-closed`
- **Domain:** go
- **Category:** system_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## 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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| google.golang.org/grpc 1.40+ | active | — | — |

## Workarounds

1. **** (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()
}
   ```
2. **** (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

- **** — Restarting does not drain in-flight handlers; the error recurs on the next shutdown. (80% fail)
- **** — Clients receive truncated responses and may retry with stale state. (75% fail)
