go network_error ai_generated true

rpc error: code = DeadlineExceeded desc = context deadline exceeded

ID: go/grpc-deadline-exceeded

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.x active — — —

Root Cause

The RPC's context deadline elapsed before the server returned a response. Common causes: server-side processing slower than the deadline, network latency, or a downstream dependency blocking the handler.

generic

中文

RPC 的上下文截止时间在服务端返回响应前已耗尽。常见原因:服务端处理慢于截止时间、网络延迟,或下游依赖阻塞了处理函数。

Workarounds

  1. 90% success
    Propagate the incoming context deadline to downstream calls and add a per-call timeout: ctx, cancel := context.WithTimeout(ctx, 2*time.Second); defer cancel(); resp, err := client.Do(ctx, req).
  2. 82% success
    Instrument server handlers with grpc.UnaryInterceptor to log elapsed time per method and identify slow handlers, then optimize or move work to a background queue.

Dead Ends

Common approaches that don't work:

  1. 75% fail

    Without a deadline, a hung server leaks goroutines and connections, eventually exhausting resources and causing cascading failures.

  2. 70% fail

    A uniformly huge deadline defeats the purpose of cancellation and still fails if the server is genuinely stuck; it also delays failure detection.