Commit 2d10f59b authored by byronap's avatar byronap

add support for ConnectTimeOutSeconds

if establishing a connection takes longer than ConnectTimeOutSeconds it will try the next address of fail the connect instead of waiting for the default timeout which is usually 20-30 seconds. Most users will want to change this to something reasonable like 6 - 10 seconds.
parent 6672cb60
...@@ -348,7 +348,38 @@ retry: ...@@ -348,7 +348,38 @@ retry:
tcpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); tcpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
} }
await tcpClient.ConnectAsync(ipAddress, port); var connectTask = tcpClient.ConnectAsync(ipAddress, port);
await Task.WhenAny(connectTask, Task.Delay(proxyServer.ConnectTimeOutSeconds * 1000));
if (!connectTask.IsCompleted || !tcpClient.Connected)
{
// here we can just do some cleanup and let the loop continue since
// we will either get a connection or wind up with a null tcpClient
// which will throw
try
{
connectTask.Dispose();
}
catch
{
// ignore
}
try
{
#if NET45
tcpClient?.Close();
#else
tcpClient?.Dispose();
#endif
tcpClient = null;
}
catch
{
// ignore
}
continue;
}
break; break;
} }
catch (Exception e) catch (Exception e)
......
...@@ -196,6 +196,12 @@ namespace Titanium.Web.Proxy ...@@ -196,6 +196,12 @@ namespace Titanium.Web.Proxy
/// </summary> /// </summary>
public int ConnectionTimeOutSeconds { get; set; } = 60; public int ConnectionTimeOutSeconds { get; set; } = 60;
/// <summary>
/// Seconds server connection are to wait for connection to be established.
/// Default value is 20 seconds.
/// </summary>
public int ConnectTimeOutSeconds { get; set; } = 20;
/// <summary> /// <summary>
/// Maximum number of concurrent connections per remote host in cache. /// Maximum number of concurrent connections per remote host in cache.
/// Only valid when connection pooling is enabled. /// Only valid when connection pooling is enabled.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment