go resource_error ai_generated true

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

ID: go/grpc-message-size-exceeded

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.40+ active
1.60+ active

Root Cause

The protobuf message exceeds gRPC's default 4 MiB receive limit. Common with large file uploads, batch arrays, or embedded blobs.

generic

中文

protobuf 消息超过 gRPC 默认 4 MiB 接收上限。常见于大文件上传、批量数组或内嵌二进制块。

Workarounds

  1. 90% success
    Raise the limit on both client and server:
    // client
    conn, _ := grpc.NewClient(addr,
      grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(16*1024*1024)))
    // server
    srv := grpc.NewServer(grpc.MaxRecvMsgSize(16*1024*1024))
  2. 95% success
    Switch large payloads to streaming RPCs:
    stream, _ := client.Upload(ctx)
    for _, chunk := range chunks { stream.Send(chunk) }
    stream.CloseAndRecv()

Dead Ends

Common approaches that don't work:

  1. 70% fail

    gRPC's limit is checked on the uncompressed logical message size in many configs; compression may not help and adds CPU cost.

  2. 95% fail

    Deterministic size violation; retries return the same error.