[grpc-java] client-side reconnect

2,011 views
Skip to first unread message

Ivan Vaskevych

unread,
Aug 25, 2016, 7:05:55 AM8/25/16
to grpc.io
Hi,

How do I use client-side backoff reconnect correctly?

Scenario: client-side streaming, plainText. When I stop the server I get the error below.
After server restart, client doesn't reconnect. That makes sense since I get onError on my StreamObserver.

What should I do on client side, recreate a channel?


client-side error logged from onError:
io.grpc.StatusRuntimeException: INTERNAL: Connection closed with unknown cause
        at io.grpc.Status.asRuntimeException(Status.java:545)
        at io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onClose(ClientCalls.java:395)
        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:481)
        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$600(ClientCallImpl.java:398)
        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:513)
        at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:52)
        at io.grpc.internal.SerializingExecutor$TaskRunner.run(SerializingExecutor.java:154)
        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:745)

Thanks!

Louis Ryan

unread,
Aug 25, 2016, 1:24:35 PM8/25/16
to Ivan Vaskevych, grpc.io
Inf-flight streams do not survive server disconnects. The Channel you created on the client will attempt to reconnect so can so you can re-start your call

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/24389235-a9ff-47c4-8987-f1d205d09364%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ivan Vaskevych

unread,
Aug 25, 2016, 4:54:22 PM8/25/16
to Louis Ryan, grpc.io
Yes, I can reuse the Channel. But I do so from the onError of my StreamObserver and it creates a new instance of self (StreamObserver). That also creates excessive logging due to constant (onError -> try to connect) cycles.

Is there a better way to do it?

Thanks!
--
Best Regards,
 Ivan

Louis Ryan

unread,
Aug 25, 2016, 6:08:18 PM8/25/16
to Ivan Vaskevych, grpc.io
You probably want to use CallOptions.withWaitForReady() so that the call queues until the transport becomes available.

Eric Anderson

unread,
Aug 25, 2016, 6:11:39 PM8/25/16
to Louis Ryan, Ivan Vaskevych, grpc.io
Note that we are aware setting wait for ready is more painful than it should be (you have to use a client interceptor today), due to these two issues.

Reply all
Reply to author
Forward
0 new messages