Please help me to understand grpc client connection error handling.
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:
// 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
}
5 connection attempts is taken and then client application is terminated if there is no service listening on certain IP:port
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.
I've tried to do the same using gRPC client but there is no method to reset channel.State
from ChannelState.TransientFailure
back to working. I know that gRPC makes pauses between connection if something is wrong:
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. https://grpc.io/grpc-java/javadoc/io/grpc/ConnectivityState.html
I can try to use WaitForStateChangedAsync
but how can I configure gRPC client to wait for certain amount of time between reconnection attempts ?
Is there any other way to connect several times and terminate client for gRPC ?
Thank you