Connection Error io.netty.handler.codec.http2.Http2Exception: HTTP/2 client preface string missing or corrupt. Hex dump for received bytes:
Asked Answered
V

3

21

Working on Grpc Bidirectional Streaming, when i try to run grpc, getting below error

Connection Error
io.netty.handler.codec.http2.Http2Exception: HTTP/2 client preface string missing or corrupt. Hex dump for received bytes: at io.netty.handler.codec.http2.Http2Exception.connectionError(Http2Exception.java:82)
    at io.netty.handler.codec.http2.Http2ConnectionHandler$PrefaceDecoder.readClientPrefaceString(Http2ConnectionHandler.java:322)
    at io.netty.handler.codec.http2.Http2ConnectionHandler$PrefaceDecoder.decode(Http2ConnectionHandler.java:263)
    at io.netty.handler.codec.http2.Http2ConnectionHandler.decode(Http2ConnectionHandler.java:445)
    at io.netty.handler.codec.ByteToMessageDecoder.decodeLast(ByteToMessageDecoder.java:382)
    at io.netty.handler.codec.ByteToMessageDecoder.channelInactive(ByteToMessageDecoder.java:286)
    at io.netty.handler.codec.http2.Http2ConnectionHandler.channelInactive(Http2ConnectionHandler.java:421)
    at io.grpc.netty.NettyServerHandler.channelInactive(NettyServerHandler.java:227)
    at io.netty.channel.ChannelHandlerInvokerUtil.invokeChannelInactiveNow(ChannelHandlerInvokerUtil.java:56)
    at io.netty.channel.DefaultChannelHandlerInvoker.invokeChannelInactive(DefaultChannelHandlerInvoker.java:92)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:135)
    at io.netty.channel.DefaultChannelPipeline.fireChannelInactive(DefaultChannelPipeline.java:928)
    at io.netty.channel.AbstractChannel$AbstractUnsafe$7.run(AbstractChannel.java:674)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:339)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:356)
    at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:742)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:748)

What could be the issue?

Ventilator answered 8/8, 2017 at 14:39 Comment(1)
You got your answer, why don't you show some appreciation by accepting it?Kemper
L
39

One thing to be aware of there is the difference between the default behavior of NettyServerBuilder and ManagedChannelBuilder w/r/t plaintext.

If you don't enable TLS on the server (eg, by calling sslContext() or useTransportSecurity() on the server builder), then you must call ManagedChannelBuilder.usePlaintext(true) on any channel connecting to the server.

So, in other words, a server is fine defaulting to plaintext, but for channels you need to call usePlaintext() to allow communication with plaintext servers. If not, you'll get this exact HTTP/2 client preface string missing or corrupt exception (although, in my case, with a particular string of bytes following the hexdump).

Luciferin answered 8/9, 2017 at 19:21 Comment(0)
L
10

The client and server aren't agreeing. Typically this is because one is plaintext and the other using TLS. But it can also be due to HTTP/1 vs HTTP/2 in certain environments.

The Hex dump for received bytes is empty though, so there's not enough information to diagnose the issue more precisely. I've never seen the bytes be empty when seeing this failure though.

Lonna answered 10/8, 2017 at 19:59 Comment(3)
I see this is an older answer, but I ran into something similar and am quite stuck. Do you have any ideas? I am following these two answers but no luck: #70311638 Is there a way to create a plaintext channel using C (Arduino project)?Boettcher
This clued in on my issue on Postman. I had used a gRPC connection which worked, then copied that connection inside of Postman. Once I did that and I tried hitting a local gRPC connection, it had this issue. I had to create a new request from scratch, then it worked.Lambent
'one is plaintext and the other using TLS' - that was a thing in my case. Good diagnosis!Gittern
V
0

While running the service locally, we need to disable TLS.

Ventilator answered 12/12, 2023 at 10:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.