title: how to handle grpc client connection errors?
body: <p>Please help me to understand grpc client connection error handling.</p>
  
  <p>I've used Micrsoft WCF before. It was easy to try to connect several times and to give up if there is no service accepting incoming connections like below:</p>
  
  <pre><code>// this is pseudo code
  int attemptCount = 0;
  while (true)
      try
      {
          client.Connect(); // exception is raised if there is not service listening for incoming connection 
          break;
      }
      catch (Exception)
      {
          client.Abort(); // to clear connection faulted state
          if (++attempCount == 5)
              throw;
          Thread.Wait(500); // waiting for service to start
      }
  
  </code></pre>
  
  <p>5 connection attempts is taken and then client application is terminated if there is no service listening on certain IP:port </p>
  
  <p>This was used when I have client and service started from VisualStudio debug at the same time so sometime client starts first and it has to wait for service to start.</p>
  
  <p>I've tried to do the same using gRPC client but there is no method to reset <code>channel.State</code> from <code>ChannelState.TransientFailure</code> back to working. I know that gRPC makes pauses between connection if something is wrong: </p>
  
  <blockquote>
    <p>For many non-fatal failures (e.g., TCP connection attempts timing out
    because the server is not yet available), the channel may spend
    increasingly large amounts of time in this state.
    <a href="https://grpc.io/grpc-java/javadoc/io/grpc/ConnectivityState.html" rel="nofollow noreferrer">https://grpc.io/grpc-java/javadoc/io/grpc/ConnectivityState.html</a></p>
  </blockquote>
  
  <p>I can try to use <code>WaitForStateChangedAsync</code> but how can I configure gRPC client to wait for certain amount of time between reconnection attempts ?</p>
  
  <p>Is there any other way to connect several times and terminate client for gRPC ?</p>
  
  <p>Thank you</p>