It is a persistent connection. But if you only have one backend (or, more importantly, one hostname, such as behind a hardware load balancer and/or proxy), the client does not create redundant connections. So there is some downtime while it re-creates a socket connection after it gets disconnected.
This downtime is usually short, so you can usually get by using a grpc.FailFast(false) call option. The default is fail-fast, which means the RPC fails if a connection is not available. But with that setting false, it will wait for the connection to become available. You should definitely use a timeout when setting fail-fast to false, so it doesn't wait too long for a connection to recover. You set a timeout via the context, as you would for other I/O that should be deadline-driven or cancellable. You can use an interceptor to set the timeout for all calls that do not already have a timeout (e.g. apply a default, so that you don't have to specify explicit timeouts everywhere in code). The interceptor can also add the fail-fast call option to every call, so you don't have to do that explicitly everywhere, too. ---- *Josh Humphries* jh...@bluegosling.com On Thu, Feb 22, 2018 at 1:57 PM, <amit.chan...@gmail.com> wrote: > Hi, > I have a question regarding the grpc Dial behavior. I have a > server, which as part of the incoming request needs to talk to another > endpoint using grpc. Currently, on the server spawn, it does grpc.Dial to > the other endpoint. and when the request comes, it does a grpc on this > established connection. Two questions: > > 1. Is the connection via grpc.Dial persistent? > 2. On the connection loss to the other endpoint, my grpc requests are > failing > err rpc error: code = Unavailable desc = all SubConns are in > TransientFailure > Do i need to dial out per request, that sounds expensive as the connection > establishment can take time. I was under the impression that Dial will > indefinitely try to establish the connection. Do i need to explicitly turn > on keepAlive to make that happen? > > 3. Also, if i want to limit how long the grpc request should take, one way > i know of is via the golang context. I was reading somewhere that the grpc > call itself, you can pass timeout. Which method is preferred? > > Thanks > Amit > > -- > 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+unsubscr...@googlegroups.com. > To post to this group, send email to grpc-io@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/c0000499-7a3c-4548-a5ca-028c03d7cc32%40googlegroups.com > <https://groups.google.com/d/msgid/grpc-io/c0000499-7a3c-4548-a5ca-028c03d7cc32%40googlegroups.com?utm_medium=email&utm_source=footer> > . > 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+unsubscr...@googlegroups.com. To post to this group, send email to grpc-io@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/CAO78j%2B%2B7cHVV5U60SpA8oyTOG32cQ4wCLDdVcC2ikioNwsWFsg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.