# UNAVAILABLE: grpc: connection closed during stream: GOAWAY received from peer

- **ID:** `grpc/connection-close-during-stream`
- **Domain:** grpc
- **Category:** network_error
- **Error Code:** `EGOAWAY`
- **Verification:** ai_generated
- **Fix Rate:** 70%

## Root Cause

The peer sent an HTTP/2 GOAWAY frame, indicating it is shutting down or reloading, causing all active streams to be terminated with an unavailable status.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| gRPC v1.59.0 | active | — | — |
| gRPC v1.62.0 | active | — | — |
| gRPC v1.65.0 | active | — | — |

## Workarounds

1. **Implement client-side retry with exponential backoff and jitter: `from grpc import exponential_backoff; for attempt in range(3): try: response = stub.Call(request); break except grpc.RpcError as e: if e.code() == grpc.StatusCode.UNAVAILABLE: time.sleep(backoff(attempt))`** (85% success)
   ```
   Implement client-side retry with exponential backoff and jitter: `from grpc import exponential_backoff; for attempt in range(3): try: response = stub.Call(request); break except grpc.RpcError as e: if e.code() == grpc.StatusCode.UNAVAILABLE: time.sleep(backoff(attempt))`
   ```
2. **Configure the server to drain connections gracefully before shutdown by setting a GOAWAY grace period: `server.graceful_shutdown(timeout=30)`** (80% success)
   ```
   Configure the server to drain connections gracefully before shutdown by setting a GOAWAY grace period: `server.graceful_shutdown(timeout=30)`
   ```
3. **Use a load balancer or proxy that can redirect traffic to healthy backends during server restarts.** (90% success)
   ```
   Use a load balancer or proxy that can redirect traffic to healthy backends during server restarts.
   ```

## Dead Ends

- **Increasing the client's retry count to 10 or more.** — If the server is permanently down, retries will all fail; retries only help with transient conditions. (60% fail)
- **Setting the environment variable GRPC_GOAWAY_MIN_PING_INTERVAL to a very low value.** — This controls ping frequency, not GOAWAY handling; it may trigger additional GOAWAYs due to excessive pings. (90% fail)
- **Switching to a different port on the same server.** — GOAWAY is sent for the entire server, not a single port; all ports are affected during shutdown. (95% fail)
