Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

grpc

grpc-java

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?

like image 304
Gayathri Avatar asked Aug 08 '17 14:08

Gayathri


2 Answers

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).

like image 143
John Hart Avatar answered Nov 09 '22 01:11

John Hart


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.

like image 23
Eric Anderson Avatar answered Nov 09 '22 02:11

Eric Anderson