diff --git a/src/Momento.Sdk/Config/Transport/IVectorIndexTransportStrategy.cs b/src/Momento.Sdk/Config/Transport/IVectorIndexTransportStrategy.cs index 78935d4e..ebaa158a 100644 --- a/src/Momento.Sdk/Config/Transport/IVectorIndexTransportStrategy.cs +++ b/src/Momento.Sdk/Config/Transport/IVectorIndexTransportStrategy.cs @@ -26,4 +26,11 @@ public interface IVectorIndexTransportStrategy /// /// A new IVectorIndexTransportStrategy with the specified client timeout public IVectorIndexTransportStrategy WithClientTimeout(TimeSpan clientTimeout); + + /// + /// Copy constructor to update the SocketsHttpHandler's options + /// + /// + /// + public IVectorIndexTransportStrategy WithSocketsHttpHandlerOptions(SocketsHttpHandlerOptions options); } diff --git a/src/Momento.Sdk/Config/Transport/StaticVectorIndexTransportStrategy.cs b/src/Momento.Sdk/Config/Transport/StaticVectorIndexTransportStrategy.cs index 90617168..46a708b3 100644 --- a/src/Momento.Sdk/Config/Transport/StaticVectorIndexTransportStrategy.cs +++ b/src/Momento.Sdk/Config/Transport/StaticVectorIndexTransportStrategy.cs @@ -37,6 +37,11 @@ public IVectorIndexTransportStrategy WithClientTimeout(TimeSpan clientTimeout) return new StaticVectorIndexTransportStrategy(_loggerFactory, GrpcConfig.WithDeadline(clientTimeout)); } + public IVectorIndexTransportStrategy WithSocketsHttpHandlerOptions(SocketsHttpHandlerOptions options) + { + return new StaticVectorIndexTransportStrategy(_loggerFactory, GrpcConfig.WithSocketsHttpHandlerOptions(options)); + } + /// /// Test equality by value. /// diff --git a/src/Momento.Sdk/Internal/GrpcManager.cs b/src/Momento.Sdk/Internal/GrpcManager.cs index da5ee315..f129dd27 100644 --- a/src/Momento.Sdk/Internal/GrpcManager.cs +++ b/src/Momento.Sdk/Internal/GrpcManager.cs @@ -75,7 +75,7 @@ internal GrpcManager(IGrpcConfiguration grpcConfig, ILoggerFactory loggerFactory 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, + KeepAlivePingPolicy = grpcConfig.SocketsHttpHandlerOptions.KeepAlivePermitWithoutCalls ? System.Net.Http.HttpKeepAlivePingPolicy.Always : System.Net.Http.HttpKeepAlivePingPolicy.WithActiveRequests, }; } #elif USE_GRPC_WEB diff --git a/src/Momento.Sdk/Internal/ScsControlClient.cs b/src/Momento.Sdk/Internal/ScsControlClient.cs index 9ec7e952..e348ccc2 100644 --- a/src/Momento.Sdk/Internal/ScsControlClient.cs +++ b/src/Momento.Sdk/Internal/ScsControlClient.cs @@ -4,6 +4,7 @@ using Microsoft.Extensions.Logging; using Momento.Protos.ControlClient; using Momento.Sdk.Config; +using Momento.Sdk.Config.Transport; using Momento.Sdk.Exceptions; using Momento.Sdk.Responses; @@ -20,7 +21,17 @@ internal sealed class ScsControlClient : IDisposable public ScsControlClient(IConfiguration config, string authToken, string endpoint) { - this.grpcManager = new ControlGrpcManager(config, authToken, endpoint); + // Override the sockets http handler options to disable keepalive + var overrideKeepalive = SocketsHttpHandlerOptions.Of( + pooledConnectionIdleTimeout: config.TransportStrategy.GrpcConfig.SocketsHttpHandlerOptions.PooledConnectionIdleTimeout, + enableMultipleHttp2Connections: config.TransportStrategy.GrpcConfig.SocketsHttpHandlerOptions.EnableMultipleHttp2Connections, + keepAlivePingTimeout: System.Threading.Timeout.InfiniteTimeSpan, + keepAlivePingDelay: System.Threading.Timeout.InfiniteTimeSpan, + keepAlivePermitWithoutCalls: false + ); + var controlConfig = config.WithTransportStrategy(config.TransportStrategy.WithSocketsHttpHandlerOptions(overrideKeepalive)); + + this.grpcManager = new ControlGrpcManager(controlConfig, authToken, endpoint); this.authToken = authToken; this._logger = config.LoggerFactory.CreateLogger(); this._exceptionMapper = new CacheExceptionMapper(config.LoggerFactory); diff --git a/src/Momento.Sdk/Internal/VectorIndexControlClient.cs b/src/Momento.Sdk/Internal/VectorIndexControlClient.cs index 8f5a9791..2f77553d 100644 --- a/src/Momento.Sdk/Internal/VectorIndexControlClient.cs +++ b/src/Momento.Sdk/Internal/VectorIndexControlClient.cs @@ -9,6 +9,7 @@ using Momento.Sdk.Requests.Vector; using Momento.Sdk.Responses.Vector; using Momento.Sdk.Config; +using Momento.Sdk.Config.Transport; namespace Momento.Sdk.Internal; @@ -22,7 +23,17 @@ internal sealed class VectorIndexControlClient : IDisposable public VectorIndexControlClient(IVectorIndexConfiguration config, string authToken, string endpoint) { - grpcManager = new VectorIndexControlGrpcManager(config, authToken, endpoint); + // Override the sockets http handler options to disable keepalive + var overrideKeepalive = SocketsHttpHandlerOptions.Of( + pooledConnectionIdleTimeout: config.TransportStrategy.GrpcConfig.SocketsHttpHandlerOptions.PooledConnectionIdleTimeout, + enableMultipleHttp2Connections: config.TransportStrategy.GrpcConfig.SocketsHttpHandlerOptions.EnableMultipleHttp2Connections, + keepAlivePingTimeout: System.Threading.Timeout.InfiniteTimeSpan, + keepAlivePingDelay: System.Threading.Timeout.InfiniteTimeSpan, + keepAlivePermitWithoutCalls: false + ); + var controlConfig = config.WithTransportStrategy(config.TransportStrategy.WithSocketsHttpHandlerOptions(overrideKeepalive)); + + grpcManager = new VectorIndexControlGrpcManager(controlConfig, authToken, endpoint); _logger = config.LoggerFactory.CreateLogger(); _exceptionMapper = new CacheExceptionMapper(config.LoggerFactory); }