diff --git a/src/Momento.Sdk/Internal/GrpcManager.cs b/src/Momento.Sdk/Internal/GrpcManager.cs index da5ee315..c25e4aee 100644 --- a/src/Momento.Sdk/Internal/GrpcManager.cs +++ b/src/Momento.Sdk/Internal/GrpcManager.cs @@ -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