How to avoid client block forever when connecting an non-exist server?

65 views
Skip to first unread message

xiaona...@gmail.com

unread,
Oct 6, 2017, 3:23:32 AM10/6/17
to grpc.io
Hi all,

Greetings from me! I find in greeter_client.cc code: 

    GreeterClient greeter(grpc::CreateChannel(
          "localhost:50051", grpc::InsecureChannelCredentials()));

If I use a fake host name, such as "badhost":  

        GreeterClient greeter(grpc::CreateChannel(
          "badhost:50051", grpc::InsecureChannelCredentials()));

I find the greet_client will block forever at my ArchLinux server. 

Is there any method to avoid this case? Thanks very much in advance!

Best Regards
Nan Xiao

Amit Saha

unread,
Oct 6, 2017, 4:06:24 AM10/6/17
to xiaona...@gmail.com, grpc.io
You could set a timeout while creating the channel. https://github.com/grpc/grpc/issues/3954 may help you.



--
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+u...@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/f7ea3e0c-aae8-4c57-bf89-58e3cf6ea3ee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nan Xiao

unread,
Oct 6, 2017, 4:29:58 AM10/6/17
to Amit Saha, grpc.io
Hi Amit,

Thanks for your response!

But I think set_deadline doesn't help. For example, if set_deadline(10
seconds), assume my client sends a very large packet whose time
exceeds 10 seconds, the client still disconnects the server although
the transmission is still on-going.

Best Regards
Nan Xiao

Amit Saha

unread,
Oct 6, 2017, 7:57:03 AM10/6/17
to Nan Xiao, grpc.io
On Fri, 6 Oct 2017 at 7:29 pm, Nan Xiao <xiaona...@gmail.com> wrote:
Hi Amit,

Thanks for your response!

But I think set_deadline doesn't help. For example, if set_deadline(10
seconds), assume my client sends a very large packet whose time
exceeds 10 seconds, the client still disconnects the server although
the transmission is still on-going.


Sorry I may have misunderstood your original query. 

Is your concern that the server is not functioning correctly, a channel is created  but a client request still blocks? 

If so, You could implement a wrapper (client interceptor) which will disconnect the client if a request takes longer than your desired timeout seconds? 

Is your c
Reply all
Reply to author
Forward
0 new messages