# grpc::RPC_STATUS_RESOURCE_EXCEEDED：接收到的消息大于最大值（N vs. M）

- **ID:** `communication/grpc-max-message-size-exceeded`
- **领域:** communication
- **类别:** resource_error
- **错误码:** `8`
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

gRPC消息大小超过配置的最大值（默认4 MB），导致服务器拒绝该负载。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| gRPC Go v1.62.0 | active | — | — |
| gRPC Python v1.60.0 | active | — | — |
| gRPC Java v1.61.0 | active | — | — |

## 解决方案

1. ```
   Increase max message size on both client and server. In Go: server := grpc.NewServer(grpc.MaxRecvMsgSize(50*1024*1024)); conn, _ := grpc.Dial(address, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(50*1024*1024)))
   ```
2. ```
   Split large payloads into multiple smaller gRPC messages or use streaming (e.g., server-streaming RPC) to send chunks.
   ```

## 无效尝试

- **Compress the message with gzip at application level only** — gRPC already supports compression; double compression can cause overhead without fixing the size limit if the uncompressed size is checked. (50% 失败率)
- **Increase server memory or swap** — The error is a hard limit on message size, not a memory shortage; increasing memory does not change the limit. (90% 失败率)
