# rpc错误：代码=资源耗尽 描述=grpc：接收到的消息大于最大值（5242880 vs. 4194304）

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

## 根因

gRPC服务器发送的响应大于客户端的最大接收消息大小（默认4 MB）。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.3 | active | — | — |

## 解决方案

1. **Increase client max receive message size in dial options.** (95% 成功率)
   ```
   conn, err := grpc.Dial(address, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(10*1024*1024)))
   ```
2. **Use streaming RPC to handle large payloads in chunks.** (85% 成功率)
   ```
   service LargeData { rpc StreamData(stream Request) returns (stream Response); }
   ```

## 无效尝试

- **Reduce the data size on the server side.** — The data is necessary; shrinking may lose information. (70% 失败率)
- **Set the max size on server only.** — The client enforces its own limit independently. (90% 失败率)
