# INTERNAL: grpc: 接收到的元数据大小超过限制

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

## 根因

gRPC元数据（头部/尾部）的大小超过了默认限制（通常为8 KB），通常是由于大型身份验证令牌或自定义头部导致。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| gRPC C++ 1.55+ | active | — | — |
| gRPC Java 1.55+ | active | — | — |
| gRPC .NET 2.50+ | active | — | — |

## 解决方案

1. ```
   Increase max metadata size on both client and server. In C++ server: builder.AddChannelArgument(GRPC_ARG_MAX_METADATA_SIZE, 16384); On client: grpc.InsecureChannelCredentials().SetMaxMetadataSize(16384)
   ```
2. ```
   Move large data (e.g., tokens) to the message body instead of metadata. In Go: send token as first field in protobuf message and extract on server side.
   ```

## 无效尝试

- **Increasing max metadata size on client only** — Server still enforces its own limit; the error may persist if server limit is not also increased. (45% 失败率)
- **Removing all custom headers** — May break authentication or routing logic that depends on headers. (30% 失败率)
