Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic when enabling gzip compression and decompression on both sides #755

Closed
vbfox opened this issue Sep 2, 2021 · 2 comments
Closed

Panic when enabling gzip compression and decompression on both sides #755

vbfox opened this issue Sep 2, 2021 · 2 comments
Labels
A-tonic C-bug Category: Something isn't working
Milestone

Comments

@vbfox
Copy link
Contributor

vbfox commented Sep 2, 2021

Bug Report

Version

tonic v0.5.2
tonic-build v0.5.2

Platform

MacOS client, Ubuntu 18.04.1 server

Crates

tonic

Description

When i'm connecting to a tonic server running with .accept_gzip().send_gzip() from a tonic client (Configured with .accept_gzip().send_gzip()) the following panic happens:

thread 'tokio-runtime-worker' panicked at 'internal error: entered unreachable code: message was compressed but `Streaming.encoding` was `None`. This is a bug in Tonic.

with a call stack looking like:

 at /rustc/5a19ffe1c2b99d9e09706cc286aad1ec0868eddb/library/core/src/panicking.rs:93:14
 15: 0x55f431a3aa1f - tonic::codec::decode::Streaming<T>::decode_chunk::{{closure}}::h719e8096eea665ab
 at /tmp/backend-rs/cargo-home/registry/src/github.com-1ecc6299db9ec823/tonic-0.5.2/src/codec/decode.rs:253:29
 16: 0x55f431a4313d - core::option::Option<T>::unwrap_or_else::h29e89e1abd973546
 at /rustc/5a19ffe1c2b99d9e09706cc286aad1ec0868eddb/library/core/src/option.rs:776:21
 17: 0x55f431a4313d - tonic::codec::decode::Streaming<T>::decode_chunk::hf9c4435208b8651e
 at /tmp/backend-rs/cargo-home/registry/src/github.com-1ecc6299db9ec823/tonic-0.5.2/src/codec/decode.rs:252:25
 18: 0x55f431a4313d - <tonic::codec::decode::Streaming<T> as futures_core::stream::Stream>::poll_next::hb0db8a78fb88befb
 at /tmp/backend-rs/cargo-home/registry/src/github.com-1ecc6299db9ec823/tonic-0.5.2/src/codec/decode.rs:305:33
 19: 0x55f4319e4226 - <core::pin::Pin<P> as futures_core::stream::Stream>::poll_next::h7062e518aec4ea9e
 at /tmp/backend-rs/cargo-home/registry/src/github.com-1ecc6299db9ec823/futures-core-0.3.17/src/stream.rs:120:9
 20: 0x55f4319e4226 - <S as futures_core::stream::TryStream>::try_poll_next::h72affe497d5efb72
 at /tmp/backend-rs/cargo-home/registry/src/github.com-1ecc6299db9ec823/futures-core-0.3.17/src/stream.rs:196:9
 21: 0x55f4319e4226 - futures_util::stream::try_stream::TryStreamExt::try_poll_next_unpin::h9e11ac983c3d6048
 at /tmp/backend-rs/cargo-home/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.17/src/stream/try_stream/mod.rs:998:9
 22: 0x55f4319e4226 - <futures_util::stream::try_stream::try_next::TryNext<St> as core::future::future::Future>::poll::h7903916b737babbd
 at /tmp/backend-rs/cargo-home/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.17/src/stream/try_stream/try_next.rs:32:9
 23: 0x55f4319e4226 - tonic::server::grpc::Grpc<T>::map_request_unary::{{closure}}::h585e5cb38347b6a9
 at /tmp/backend-rs/cargo-home/registry/src/github.com-1ecc6299db9ec823/tonic-0.5.2/src/server/grpc.rs:349:23
 24: 0x55f4319e4226 - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h3b8286d3d7b50009
 at /rustc/5a19ffe1c2b99d9e09706cc286aad1ec0868eddb/library/core/src/future/mod.rs:80:19
 25: 0x55f4319e4226 - tonic::server::grpc::Grpc<T>::unary::{{closure}}::h14ab60ff4ab397ed
 at /tmp/backend-rs/cargo-home/registry/src/github.com-1ecc6299db9ec823/tonic-0.5.2/src/server/grpc.rs:185:29
 26: 0x55f4319e4226 - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h681afa6e3228c7a5
 at /rustc/5a19ffe1c2b99d9e09706cc286aad1ec0868eddb/library/core/src/future/mod.rs:80:19
 27: 0x55f4319e4226 - <my_service as tower_service::Service<http::request::Request<B>>>::call::{{closure}}::hfdfe97bf1d8cee6a

@davidpdrsn davidpdrsn added A-tonic C-bug Category: Something isn't working labels Sep 2, 2021
@vbfox
Copy link
Contributor Author

vbfox commented Sep 2, 2021

I didn't fully debug yet, but suspect from a quick read of the current code that there are 2 problems here:

  • Setting send_gzip() on clients doesn't send the expected header
  • Receiving a compressed message without any header shouldn't panic but respond as specified in https://grpc.github.io/grpc/core/md_doc_compression.html

    An ill-constructed message with its Compressed-Flag bit set but lacking a grpc-encoding entry different from identity in its metadata MUST fail with INTERNAL status, its associated description indicating the invalid Compressed-Flag condition.

@LucioFranco
Copy link
Member

#763 fixes this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tonic C-bug Category: Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants