Set keepalive for gRPC in c # client

I am using a gRPC client in C # and using a long lived duplex stream. However, the TCP connection closes at some time and so I would like to use keepalive on the client. The server (written in Go) is already configured correctly for keepalive and has already been tested with clients written in Go.

I am using the following code to set keepalive for 5 minutes, and also to enable trace to see all incoming / outgoing bytes.

Environment.SetEnvironmentVariable("GRPC_TRACE", "tcp,channel,http,secure_endpoint");
Environment.SetEnvironmentVariable("GRPC_VERBOSITY", "DEBUG");

var callCredentials = CallCredentials.FromInterceptor(Interceptor());

var roots = Encoding.UTF8.GetString(Resources.roots);

Channel = new Channel(address, ChannelCredentials.Create(new SslCredentials(roots), callCredentials), new[]
{
    new ChannelOption("grpc.keepalive_time_ms", 5 * 60 *  1000), // 5 minutes
});

await Channel.ConnectAsync(DateTime.UtcNow.AddSeconds(5));

      

However, there are no bytes in the log sent after 5 minutes and the connection is closed as I can no longer send / receive messages through the same thread after the thread has been idle for a while.

How to enable keepalive correctly?

+3
c # grpc


source to share


No one has answered this question yet

Check out similar questions:

6155
What is the difference between string and string in C #?
3575
How to list an enumeration?
2964
How to cast int to enum?
2397
What are the correct version numbers for C #?
2058
How do I get a consistent byte representation of strings in C # without manually specifying the encoding?
1743
What's the best way to give a C # auto property an initial value?
1742
How to calculate a person's age in C #?
1476
Hidden features of C #?
2
GRPC client doesn't use grpc-lb even with load balancing address
0
GRPC channel remains open in C #



All Articles
Loading...
X
Show
Funny
Dev
Pics