# rpc错误：代码=数据丢失 描述=消息校验和不匹配：期望0x1234，得到0x5678

- **ID:** `go/grpc-data-loss-message-corrupted`
- **领域:** go
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

protobuf消息在传输过程中被损坏，导致校验和验证失败。

## 版本兼容性

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

## 解决方案

1. **Implement retry with a new context to avoid reusing corrupted data.** (80% 成功率)
   ```
   for i := 0; i < 3; i++ {
    ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
    resp, err := client.SomeRPC(ctx, req)
    cancel()
    if err == nil { return resp }
    if status.Code(err) != codes.DataLoss { return err }
    time.Sleep(100 * time.Millisecond)
}
   ```
2. **Use a reliable transport like TLS to reduce corruption.** (95% 成功率)
   ```
   conn, err := grpc.Dial("localhost:8080", grpc.WithTransportCredentials(creds))
   ```

## 无效尝试

- **Ignore the checksum and resend the same message.** — The same corruption may occur again if the underlying network issue persists. (70% 失败率)
- **Disable checksum validation on the server.** — This compromises data integrity and is not recommended. (90% 失败率)
