# gRPC error: DEADLINE_EXCEEDED: Stream closed with deadline exceeded

- **ID:** `api/grpc-error-deadline-exceeded-streaming`
- **Domain:** api
- **Category:** runtime_error
- **Error Code:** `4`
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A gRPC streaming RPC exceeded its configured deadline (timeout) due to slow server processing or network latency, causing the stream to be terminated.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| gRPC 1.50+ | active | — | — |
| gRPC-Go 1.50+ | active | — | — |
| gRPC-Java 1.50+ | active | — | — |
| gRPC-Python 1.50+ | active | — | — |

## Workarounds

1. **Set a reasonable deadline on the client and implement retries with backoff. Example in Go:
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
stream, err := client.StreamingRPC(ctx, req)
if err == context.DeadlineExceeded {
    // Implement retry logic
    time.Sleep(2 * time.Second)
    // Retry with new context
}** (85% success)
   ```
   Set a reasonable deadline on the client and implement retries with backoff. Example in Go:
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
stream, err := client.StreamingRPC(ctx, req)
if err == context.DeadlineExceeded {
    // Implement retry logic
    time.Sleep(2 * time.Second)
    // Retry with new context
}
   ```
2. **Optimize server-side processing to reduce latency, such as by using connection pooling or caching.** (80% success)
   ```
   Optimize server-side processing to reduce latency, such as by using connection pooling or caching.
   ```
3. **If network latency is high, use a gRPC proxy or consider deploying the server closer to the client.** (75% success)
   ```
   If network latency is high, use a gRPC proxy or consider deploying the server closer to the client.
   ```

## Dead Ends

- **** — This only masks the issue; if the server is slow, the stream may still timeout or the client may hang indefinitely. (40% fail)
- **** — This can lead to resource leaks and hangs; also, the server may still enforce its own deadline. (70% fail)
- **** — This changes the API contract and may break functionality that relies on streaming. (60% fail)
