# Tonic reports invalid flag err but it's not

**URL:** <https://users.rust-lang.org/t/tonic-reports-invalid-flag-err-but-its-not/77751>\
**Category:** help\
**Created:** [July 1, 2022, 11:05am UTC](https://users.rust-lang.org/t/tonic-reports-invalid-flag-err-but-its-not/77751 "2022-07-01T11:05:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TENX](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/tenx/32/25180_2.png) [@TENX](https://users.rust-lang.org/u/TENX)\
**Post date:** [July 1, 2022, 11:05am UTC](https://users.rust-lang.org/t/tonic-reports-invalid-flag-err-but-its-not/77751/1 "2022-07-01T11:05:26Z")

</div>

Hi,  
I'm trying to send a dynamic gRPC message by using [rust-protobuf](https://github.com/stepancheg/rust-protobuf) and [tonic](https://github.com/hyperium/tonic). Here's my [attempt](https://github.com/TENX-S/attempt). It's almost there, but with an odd error.  
To use it, start the server first, then the client.  
And we will see the following output:

```nohighlight
request: {"name": "World"}
reply: {"message": "Hello World!"}
Err(
    Status {
        code: Internal,
        message: "protocol error: received message with invalid compression flag: 10 (valid flags are 0 and 1) while receiving response with status: 200 OK",
        source: None,
    },
)

```

It says "invalid compression flag". Alright, let's get the packet:

 ![176588254-93f7a749-f291-4865-ab2f-9993286f423a](https://us1.discourse-cdn.com/flex019/uploads/rust_lang/original/3X/d/4/d4384a84d6e3f4e1f8a9eacf2407f2a82e1b9754.jpeg)  
and... I'm lost here.

---

<div class="post-metadata">

**Author:** ![TENX](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/tenx/32/25180_2.png) [@TENX](https://users.rust-lang.org/u/TENX)\
**Post date:** [July 1, 2022, 12:05pm UTC](https://users.rust-lang.org/t/tonic-reports-invalid-flag-err-but-its-not/77751/2 "2022-07-01T12:05:46Z")

</div>

I've been debugging it for a while. It seems like the Err is returned here:

> <https://github.com/hyperium/tonic/blob/9ea03c2c44ad6bf76e4141e6fb40870b9b30ab63/tonic/src/codec/decode.rs#L173>

it will jump to:

> <https://github.com/hyperium/tonic/blob/9ea03c2c44ad6bf76e4141e6fb40870b9b30ab63/tonic/src/codec/decode.rs#L143>

then:

> <https://github.com/hyperium/tonic/blob/9ea03c2c44ad6bf76e4141e6fb40870b9b30ab63/tonic/src/codec/decode.rs#L290>

and we got the "invalid compression flag" here:

> <https://github.com/tokio-rs/bytes/blob/28a1eab1e0531a0e7b9624e474a8c06dfd5c8072/src/buf/buf_impl.rs#L289>

![image](https://user-images.githubusercontent.com/40336192/176890127-8f64327b-cd48-4d69-8043-66f2032a9b4a.png)

It seems like the error arises when tonic try to fetch the trailers and clear the body. But it's not the correct body?

---

<div class="post-metadata">

**Author:** ![TENX](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/tenx/32/25180_2.png) [@TENX](https://users.rust-lang.org/u/TENX)\
**Post date:** [July 2, 2022, 3:23am UTC](https://users.rust-lang.org/t/tonic-reports-invalid-flag-err-but-its-not/77751/3 "2022-07-02T03:23:16Z")

</div>

Problem solved. In case if anyone interested in, here's the [context](https://github.com/hyperium/tonic/issues/1029).

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/system/32/51372_2.png) [@system](https://users.rust-lang.org/u/system)\
**Post date:** [September 30, 2022, 3:24am UTC](https://users.rust-lang.org/t/tonic-reports-invalid-flag-err-but-its-not/77751/4 "2022-09-30T03:24:14Z")

</div>

Closed on September 30, 2022, 3:24am UTC

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.
