# RESOURCE_EXHAUSTED: grpc: 接收的消息超过最大限制 (5242880 vs. 4194304)

- **ID:** `grpc/grpc-message-too-large-client`
- **领域:** grpc
- **类别:** resource_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

客户端接收到的 gRPC 响应消息超过了配置的最大接收消息大小。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| gRPC v1.48.0 | active | — | — |
| gRPC v1.56.0 | active | — | — |
| gRPC v1.62.0 | active | — | — |

## 解决方案

1. ```
   Increase the client's max receive message size using grpc.max_receive_message_length option. Example in Python: channel = grpc.insecure_channel('localhost:50051', options=[('grpc.max_receive_message_length', 10 * 1024 * 1024)])
   ```
2. ```
   Set the environment variable GRPC_MAX_RECEIVE_MESSAGE_LENGTH to a larger value (e.g., 10485760 for 10 MB) before starting the client process.
   ```
3. ```
   Refactor the RPC to use streaming responses or pagination to avoid sending large messages in a single response.
   ```

## 无效尝试

- **** — The error occurs on the client side; server-side changes alone don't fix client-side limits. (80% 失败率)
- **** — Compression may reduce size but doesn't guarantee it stays under the limit; also adds overhead. (60% 失败率)
- **** — The same large message will be received again unless the client limit is increased. (95% 失败率)
