go network_error ai_generated true

rpc error: code = DeadlineExceeded desc = context deadline exceeded

ID: go/grpc-deadline-exceeded-context

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
google.golang.org/grpc v1.40+ active

Root Cause

The client-side or server-side context deadline elapsed before the RPC completed. Common when the server is slow, the network is congested, or the deadline is set too aggressively relative to the handler's work.

generic

中文

在 RPC 完成前,客户端或服务端的上下文截止时间已到。常见于服务端处理缓慢、网络拥塞,或相对于处理逻辑而言截止时间设置过短。

Workarounds

  1. 85% success
    ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
    defer cancel()
    resp, err := client.Do(ctx, req)
    if status.Code(err) == codes.DeadlineExceeded {
        // retry with backoff
    }
  2. 80% success
    // measure handler latency, then set client deadline > p99
    ctx, cancel := context.WithTimeout(ctx, p99Latency*2)
    defer cancel()

Dead Ends

Common approaches that don't work:

  1. 80% fail

    If the server is genuinely overloaded, tight retries amplify load and worsen latency, causing more timeouts. No jitter means thundering herd.

  2. 75% fail

    Unbounded calls leak goroutines and hold connections indefinitely when the server hangs, eventually exhausting resources.