# rpc 错误：code = ResourceExhausted desc = grpc: 接收到的消息超过最大值（5242881 vs. 4194304）

- **ID:** `go/grpc-resource-exhausted-max-message-size`
- **领域:** go
- **类别:** resource_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.x | active | — | — |

## 解决方案

1. **** (90% 成功率)
   ```
   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% 成功率)
   ```
   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.
   ```

## 无效尝试

- **** — Compression reduces wire size but the decompressed message is still checked against MaxRecvMsgSize, so large payloads still fail. (70% 失败率)
- **** — The server also enforces the limit when receiving the request/response, so the error moves to the server side. (65% 失败率)
