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

只谈情不闲聊 提交于 2021-02-18 10:59:38

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/45571314/connection-error-io-netty-handler-codec-http2-http2exception-http-2-client-pref

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!