# INTERNAL: grpc: 压缩算法协商失败

- **ID:** `grpc/compression-negotiation-failed`
- **领域:** grpc
- **类别:** protocol_error
- **验证级别:** ai_generated
- **修复率:** 75%

## 根因

客户端和服务器不支持共同的压缩算法；客户端发送的消息使用了不支持的算法，或者服务器在握手期间拒绝了提议的算法。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| gRPC C++ 1.45+ | active | — | — |
| gRPC Go 1.45+ | active | — | — |
| gRPC Python 1.45+ | active | — | — |

## 解决方案

1. ```
   Ensure both client and server use the same compression algorithm. Set client-side: grpc.WithDefaultCallOptions(grpc.UseCompressor("gzip")) in Go. On server, register compressor: import "google.golang.org/grpc/encoding/gzip"
   ```
2. ```
   Upgrade gRPC libraries to latest versions to support modern compression algorithms like gzip or snappy. In Python: pip install grpcio==1.60.0 and set grpc.Compression.Gzip
   ```

## 无效尝试

- **Enabling all compression algorithms on both sides** — May increase memory usage and latency; also some algorithms (e.g., deflate) are deprecated and may cause interoperability issues. (35% 失败率)
- **Disabling compression entirely** — Increases bandwidth usage; may not be acceptable for high-volume services. (25% 失败率)
