Simple Sample, bu "An existing connection was forcibly closed by the remote host"

572 views
Skip to first unread message

nicolas...@gmail.com

unread,
Jun 28, 2016, 9:52:05 AM6/28/16
to grpc.io
Hi all,

I am new in protobuff... and I already need some help.

Here a simple sample I have successfuly created, a simple service which getData from a server..
I get an error (An existing connection was forcibly closed by the remote host), just after the client received the final acknowledgement.
It means I can not use ma servezr more than once :)

I am using, on windows7,

Java 8
protoc:3.0.0-beta-2
protoc-gen-grpc-java:0.14.0
protobuf-maven-plugin 0.5.0
grpc-netty 0.14.0
grpc-protobuf 0.14.0
grpc-stub 0.14.0



On Client Side,

ManagedChannel channel = ManagedChannelBuilder.forAddress(host, port)
 
.usePlaintext(true)
 
.build();ViewServiceGrpc.ViewServiceBlockingClient blockingStub = ViewServiceGrpc.newBlockingStub(channel);
blockingStub
.getData();
channel.shutdown();



On the server Side:


server
= ServerBuilder.forPort(port).addService(ViewServiceGrpc.bindService(new ViewServiceGrpc.ViewService() {
 
public void getData(View request, StreamObserver<Ack> responseObserver) {
 
switch (request.getDataCase()) {
 
 responseObserver
.onNext(Ack.newBuilder().setAckMessage("ACK_OK").build());
 responseObserver
.onCompleted();
 
}

 
})).build();
 server
.start();

Everything is OK, except this error on server side

juin 28, 2016 3:33:47 PM io.grpc.netty.NettyServerHandler onConnectionError AVERTISSEMENT: Connection Error java.io.IOException: Une connexion existante a dû être fermée par lhôte distant at sun.nio.ch.SocketDispatcher.read0(Native Method) at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43) at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223) at sun.nio.ch.IOUtil.read(IOUtil.java:192) at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380) at io.netty.buffer.PooledUnsafeDirectByteBuf.setBytes(PooledUnsafeDirectByteBuf.java:288) at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1054) at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:245) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:106) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:527) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:484) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:398) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:370) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:742) at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:145) at java.lang.Thread.run(Thread.java:745) juin 28, 2016 3:33:47 PM io.grpc.netty.NettyServerTransport notifyTerminated GRAVE: Transport failed java.io.IOException: Une connexion existante a dû être fermée par lhôte distant at sun.nio.ch.SocketDispatcher.read0(Native Method) at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43) at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223) at sun.nio.ch.IOUtil.read(IOUtil.java:192) at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380) at io.netty.buffer.PooledUnsafeDirectByteBuf.setBytes(PooledUnsafeDirectByteBuf.java:288) at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1054) at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:245) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:106) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:527) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:484) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:398) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:370) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:742) at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:145) at java.lang.Thread.run(Thread.java:745)



Thanks for your help.

Nicolas Vacelet

unread,
Jun 29, 2016, 2:50:13 AM6/29/16
to grpc.io
I answer to Myself;

To correctly close the client, and avoid an exception, one should use 

channel.shutdown.awaitTermination(5, SECONDS)

--
You received this message because you are subscribed to a topic in the Google Groups "grpc.io" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/grpc-io/xcKtw8EZEtI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to grpc-io+u...@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/43de1809-ea84-4c05-96cd-465dc430951b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Eric Anderson

unread,
Jun 29, 2016, 11:56:16 AM6/29/16
to Nicolas Vacelet, grpc.io
Sorry, I was going to reply with something like that yesterday and things came up. Glad you got it working.

It means I can not use ma servezr more than once

However, the server shouldn't die even without the awaitTermination(). Future clients should work fine. If not, that's a bug.

To unsubscribe from this group and all its topics, send an email to grpc-io+unsubscribe@googlegroups.com.

To post to this group, send email to grp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/43de1809-ea84-4c05-96cd-465dc430951b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscribe@googlegroups.com.

To post to this group, send email to grp...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages