INTERNAL: compression dictionary mismatch: expected gzip but received deflate
ID: grpc/compression-dictionary-mismatch
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| gRPC v1.63.0 | active | — | — | — |
| gRPC-Python v1.62.0 | active | — | — | — |
| gRPC-Go v1.64.0 | active | — | — | — |
Root Cause
gRPC message compression algorithm mismatch between client and server: the client sends a message compressed with 'deflate' but the server expects 'gzip', or vice versa, due to incompatible compression configuration.
generic中文
客户端和服务器之间的gRPC消息压缩算法不匹配:客户端发送使用'deflate'压缩的消息,但服务器期望'gzip',反之亦然,由于压缩配置不兼容。
Official Documentation
https://grpc.io/docs/guides/compression/Workarounds
-
90% success Align compression algorithms: set the same compression on both client and server; e.g., in Python: 'grpc.insecure_channel(target, options=[("grpc.default_compression_algorithm", 2)])' (2=gzip) and on server: 'grpc.server(futures.ThreadPoolExecutor(), options=[("grpc.default_compression_algorithm", 2)])'.
Align compression algorithms: set the same compression on both client and server; e.g., in Python: 'grpc.insecure_channel(target, options=[("grpc.default_compression_algorithm", 2)])' (2=gzip) and on server: 'grpc.server(futures.ThreadPoolExecutor(), options=[("grpc.default_compression_algorithm", 2)])'. -
85% success Use environment variables to override compression: set 'GRPC_DEFAULT_COMPRESSION_ALGORITHM=gzip' on both client and server to enforce consistency, and 'GRPC_DEFAULT_COMPRESSION_LEVEL=1' for low latency.
Use environment variables to override compression: set 'GRPC_DEFAULT_COMPRESSION_ALGORITHM=gzip' on both client and server to enforce consistency, and 'GRPC_DEFAULT_COMPRESSION_LEVEL=1' for low latency.
-
75% success Implement a client-side interceptor to detect and log compression headers: inspect 'grpc-encoding' metadata and adjust the algorithm dynamically if mismatch is detected; fall back to no compression if negotiation fails.
Implement a client-side interceptor to detect and log compression headers: inspect 'grpc-encoding' metadata and adjust the algorithm dynamically if mismatch is detected; fall back to no compression if negotiation fails.
中文步骤
对齐压缩算法:在客户端和服务器上设置相同的压缩;例如在Python中:'grpc.insecure_channel(target, options=[("grpc.default_compression_algorithm", 2)])'(2=gzip),服务器上:'grpc.server(futures.ThreadPoolExecutor(), options=[("grpc.default_compression_algorithm", 2)])'。使用环境变量覆盖压缩:在客户端和服务器上设置'GRPC_DEFAULT_COMPRESSION_ALGORITHM=gzip'以强制一致性,并设置'GRPC_DEFAULT_COMPRESSION_LEVEL=1'以实现低延迟。
实现客户端拦截器检测和记录压缩头部:检查'grpc-encoding'元数据,并在检测到不匹配时动态调整算法;如果协商失败,回退到无压缩。
Dead Ends
Common approaches that don't work:
-
75% fail
Disabling compression entirely on the client side (e.g., 'grpc.default_compression_algorithm=none') may break if the server requires compression; the error changes to 'UNIMPLEMENTED: Decompressor is not installed'.
-
85% fail
Switching to a third compression library (e.g., zstd) without updating both sides causes a new mismatch error; both client and server must agree on the algorithm.
-
95% fail
Restarting the server with the same configuration doesn't fix the root cause; the mismatch persists until the client's compression algorithm is changed.