Skip to content

Commit

Permalink
fix: disable keepalive for control clients
Browse files Browse the repository at this point in the history
  • Loading branch information
anitarua committed Mar 5, 2024
1 parent 4db09f8 commit 8b6ecf3
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/Momento.Sdk/Internal/GrpcManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,24 @@ internal GrpcManager(IGrpcConfiguration grpcConfig, ILoggerFactory loggerFactory
#if NET5_0_OR_GREATER
if (SocketsHttpHandler.IsSupported) // see: https://github.com/grpc/grpc-dotnet/blob/098dca892a3949ade411c3f2f66003f7b330dfd2/src/Shared/HttpHandlerFactory.cs#L28-L30
{
var keepAliveWithoutCallsPolicy = grpcConfig.SocketsHttpHandlerOptions.KeepAlivePermitWithoutCalls == true ? System.Net.Http.HttpKeepAlivePingPolicy.Always : System.Net.Http.HttpKeepAlivePingPolicy.WithActiveRequests;
var keepAliveTimeout = grpcConfig.SocketsHttpHandlerOptions.KeepAlivePingTimeout;
var keepAlivePingDelay = grpcConfig.SocketsHttpHandlerOptions.KeepAlivePingDelay;

// Disable keepalives for control clients and convert KeepAlivePermitWithoutCalls from bool to HttpKeepAlivePingPolicy
if (loggerName.Contains("Control")) {
keepAliveWithoutCallsPolicy = System.Net.Http.HttpKeepAlivePingPolicy.WithActiveRequests;
keepAliveTimeout = System.Threading.Timeout.InfiniteTimeSpan;
keepAlivePingDelay = System.Threading.Timeout.InfiniteTimeSpan;
}

channelOptions.HttpHandler = new SocketsHttpHandler
{
EnableMultipleHttp2Connections = grpcConfig.SocketsHttpHandlerOptions.EnableMultipleHttp2Connections,
PooledConnectionIdleTimeout = grpcConfig.SocketsHttpHandlerOptions.PooledConnectionIdleTimeout,
KeepAlivePingTimeout = grpcConfig.SocketsHttpHandlerOptions.KeepAlivePingTimeout,
KeepAlivePingDelay = grpcConfig.SocketsHttpHandlerOptions.KeepAlivePingDelay,
KeepAlivePingPolicy = grpcConfig.SocketsHttpHandlerOptions.KeepAlivePermitWithoutCalls == true ? System.Net.Http.HttpKeepAlivePingPolicy.Always : System.Net.Http.HttpKeepAlivePingPolicy.WithActiveRequests,
KeepAlivePingTimeout = keepAliveTimeout,
KeepAlivePingDelay = keepAlivePingDelay,
KeepAlivePingPolicy = keepAliveWithoutCallsPolicy,
};
}
#elif USE_GRPC_WEB
Expand Down

0 comments on commit 8b6ecf3

Please sign in to comment.