go resource_error ai_generated true

rpc error: code = ResourceExhausted desc = grpc: received message larger than max (5242881 vs. 4194304)

ID: go/grpc-resource-exhausted-max-message-size

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.x active — — —

Root Cause

The serialized message exceeds the default 4 MiB receive limit. gRPC enforces MaxRecvMsgSize on both client and server.

generic

中文

序列化后的消息超过了默认 4 MiB 的接收限制。gRPC 在客户端和服务端都强制 MaxRecvMsgSize。

Workarounds

  1. 90% success
    Raise the limit on both sides: grpc.NewServer(grpc.MaxRecvMsgSize(16*1024*1024)) and grpc.Dial(addr, grpc.WithDefaultCallOptions(grpc.MaxRecvMsgSize(16*1024*1024))).
  2. 85% success
    Switch large payloads to gRPC streaming (client-streaming or server-streaming) so each message stays small, or store blobs out-of-band and pass a reference.

Dead Ends

Common approaches that don't work:

  1. 70% fail

    Compression reduces wire size but the decompressed message is still checked against MaxRecvMsgSize, so large payloads still fail.

  2. 65% fail

    The server also enforces the limit when receiving the request/response, so the error moves to the server side.