grpc-java icon indicating copy to clipboard operation
grpc-java copied to clipboard

First received frame was not SETTINGS. Hex dump for first 5 bytes: 1503010002

Open yuzheng21 opened this issue 8 years ago • 3 comments

Please answer these questions before submitting your issue.

What version of gRPC are you using?

1.6.1

What JVM are you using (java -version)? java version "1.8.0_144" Java(TM) SE Runtime Environment (build 1.8.0_144-b01) Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

What did you do?

I ran a grpc server (in Golang) and a client (in Java) that accessed this server. The error occurred always when I tried to send request to server via a blockingStub

blockingStub = AgentGrpc.newBlockingStub(ManagedChannelBuilder.forAddress(host, port).usePlaintext(true).build());

What did you expect to see?

Successful call

What did you see instead?

io.grpc.StatusRuntimeException: INTERNAL
	at io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:210)
	at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:191)
	at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:124)
	at com.ibm.watson.serve.agent.AgentGrpc$AgentBlockingStub.pushServerStatus(AgentGrpc.java:281)
	at com.ibm.watson.model_serving.AgentClient.sendServerStatus(AgentClient.java:32)
	at com.ibm.watson.model_serving.ServerExample$ServerExampleService.addModel(ServerExample.java:463)
	at com.ibm.watson.serve.runtime.ServiceRuntimeGrpc$MethodHandlers.invoke(ServiceRuntimeGrpc.java:593)
	at io.grpc.stub.ServerCalls$UnaryServerCallHandler$UnaryServerCallListener.onHalfClose(ServerCalls.java:174)
	at io.grpc.internal.ServerCallImpl$ServerStreamListenerImpl.halfClosed(ServerCallImpl.java:272)
	at io.grpc.internal.ServerImpl$JumpToApplicationThreadServerStreamListener$2.runInContext(ServerImpl.java:594)
	at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
	at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:102)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: io.netty.handler.codec.http2.Http2Exception: First received frame was not SETTINGS. Hex dump for first 5 bytes: 1503010002
	at io.netty.handler.codec.http2.Http2Exception.connectionError(Http2Exception.java:85)
	at io.netty.handler.codec.http2.Http2ConnectionHandler$PrefaceDecoder.verifyFirstFrameIsSettings(Http2ConnectionHandler.java:321)
	at io.netty.handler.codec.http2.Http2ConnectionHandler$PrefaceDecoder.decode(Http2ConnectionHandler.java:222)
	at io.netty.handler.codec.http2.Http2ConnectionHandler.decode(Http2ConnectionHandler.java:414)
	at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:489)
	at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:428)
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:265)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1342)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:934)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:134)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459)
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
	at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:138)
	... 1 more

yuzheng21 avatar Feb 09 '18 22:02 yuzheng21

This is usually because the server is using SSL, but the client is not.

You should avoid using plaintext.

carl-mastrangelo avatar Feb 12 '18 19:02 carl-mastrangelo

@carl-mastrangelo yeah, I just found the mistake. thanks!

yuzheng21 avatar Feb 12 '18 23:02 yuzheng21

For posterity, here's the break down of the header.

1503010002 a TLS record, similar to the server hello.
However, in this case it's an alert record type indicating an error.

  • 15 in the beginning the record is not a handshake, but an alert (SSL3_RT_ALERT), which is a warning or fatal error.
  • The following two bytes 0301 indicate the version of the TSL is 1.0: TLS1_VERSION x'0301'
  • The rest of the record 0002 indicates the length of the alert data following the record is two bytes.

SSL record format info: https://www.ibm.com/docs/en/ztpf/2023?topic=sessions-ssl-record-format

sergiitk avatar Nov 21 '23 19:11 sergiitk