Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Added winHttpHandler TcpKeepAlive #522

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/csharp/ArmoniK.Api.Client/Submitter/GrpcChannelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ public static class GrpcChannelFactory
/// <param name="proxy">Proxy configuration to use</param>
/// <param name="proxyType">Type of the proxy used</param>
/// <param name="handlerType">Which HttpMessageHandler type to use</param>
/// <param name="keepAliveTime">TCP KeepAlive time</param>
/// <param name="keepAliveTimeInterval">TCP KeepAlive time interval</param>
/// <param name="logger">Optional logger</param>
/// <returns>HttpMessageHandler</returns>
private static HttpMessageHandler CreateHttpMessageHandler(bool https,
Expand All @@ -146,6 +148,8 @@ private static HttpMessageHandler CreateHttpMessageHandler(bool htt
IWebProxy? proxy,
ProxyType proxyType,
HandlerType handlerType,
TimeSpan keepAliveTime,
TimeSpan keepAliveTimeInterval,
ILogger? logger = null)
{
Func<HttpRequestMessage, X509Certificate2, X509Chain, SslPolicyErrors, bool>? validationCallback = null;
Expand Down Expand Up @@ -199,6 +203,15 @@ private static HttpMessageHandler CreateHttpMessageHandler(bool htt
}

var winHandler = new WinHttpHandler();
try
{
winHandler.TcpKeepAliveEnabled = true;
winHandler.TcpKeepAliveTime = keepAliveTime;
winHandler.TcpKeepAliveInterval = keepAliveTimeInterval;
}
catch (NotSupportedException)
{
}

if (https)
{
Expand Down Expand Up @@ -387,6 +400,8 @@ private static GrpcChannel CreateChannelInternal(GrpcClient optionsGrpcClient,
proxy,
proxyType,
handlerType,
optionsGrpcClient.KeepAliveTime,
optionsGrpcClient.KeepAliveTimeInterval,
logger);

// Warn that RequestTimeout is not supported.
Expand Down
Loading