I have a gRPC streaming client, that has to handle server going up and down, so I have a while loop, but sometimes it works fine, but other times it takes 15 seconds to connect even on the same machine. Is it something wrong with my code, or how can I debug? As you can see below I have debug to print out channel state, and is mostly
GRPC_CHANNEL_CONNECTING or
GRPC_CHANNEL_TRANSIENT_FAILURE , but still can take 15 seconds to connect. I haven't found a pattern. Can someone tell me how I get it to connect faster and more reliably? Thanks. Note I am using a deadline, so that I can shut everything down at the end gracefully, and not have it block forever.
...
channel = grpc::CreateChannel(asServerAddress, channel_creds);
while ((channel->GetState(true) != GRPC_CHANNEL_READY))
{
time_point deadline = std::chrono::system_clock::now() + std::chrono::milliseconds(1000);
channel->WaitForConnected(deadline);
std::cout << "." << channel->GetState(false) << std::flush ;
}
std::cout << "Client Connected" << std::endl;
....