{
  "id": "go/grpc-resource-exhausted-message-larger-than-max",
  "signature": "rpc error: code = ResourceExhausted desc = grpc: received message larger than max (5242881 vs. 4194304)",
  "signature_zh": "rpc 错误：code = ResourceExhausted desc = grpc：接收到的消息大于最大值（5242881 vs. 4194304）",
  "regex": "rpc\\ error:\\ code\\ =\\ ResourceExhausted\\ desc\\ =\\ grpc:\\ received\\ message\\ larger\\ than\\ max\\ \\(5242881\\ vs\\.\\ 4194304\\)",
  "domain": "go",
  "category": "resource_error",
  "subcategory": null,
  "root_cause": "The received message exceeds the default 4 MiB max receive size (grpc.MaxRecvMsgSize). gRPC rejects messages above the configured limit to protect memory. The default is 4 MiB for both send and receive.",
  "root_cause_type": "generic",
  "root_cause_zh": "接收到的消息超过了默认的 4 MiB 最大接收大小（grpc.MaxRecvMsgSize）。gRPC 会拒绝超过配置限制的消息以保护内存。发送和接收的默认值均为 4 MiB。",
  "versions": [
    {
      "version": "1.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The max-size check is applied to the uncompressed message on the receiving side, so compression does not raise the limit and the error persists.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Allowing unbounded messages exposes the service to OOM from a single malicious or buggy client; the protection exists for a reason.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Raise the limit deliberately on both ends to a value you can justify:\n\nsrv := grpc.NewServer(grpc.MaxRecvMsgSize(16<<20), grpc.MaxSendMsgSize(16<<20))\nconn, _ := grpc.Dial(addr, grpc.WithDefaultCallOptions(\n    grpc.MaxCallRecvMsgSize(16<<20),\n    grpc.MaxCallSendMsgSize(16<<20)))",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.88,
      "how": "For genuinely large payloads, switch to client/server streaming instead of a unary message:\n\nstream, _ := client.Upload(ctx)\nfor _, chunk := range chunks { stream.Send(&pb.Chunk{Data: chunk}) }\n_, err := stream.CloseAndRecv()",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.89,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-02-14",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}