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 zero connection timeout issue in Managed SNI #332

Merged
merged 11 commits into from
Nov 28, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public SNITCPHandle(string serverName, int port, long timerExpire, object callba
}
else
{
_socket = Connect(serverName, port, ts);
_socket = Connect(serverName, port, ts, isInfiniteTimeOut);
}

if (_socket == null || !_socket.Connected)
Expand Down Expand Up @@ -179,7 +179,7 @@ public SNITCPHandle(string serverName, int port, long timerExpire, object callba
_status = TdsEnums.SNI_SUCCESS;
}

private static Socket Connect(string serverName, int port, TimeSpan timeout)
private static Socket Connect(string serverName, int port, TimeSpan timeout, bool isInfiniteTimeout)
{
IPAddress[] ipAddresses = Dns.GetHostAddresses(serverName);
IPAddress serverIPv4 = null;
Expand All @@ -199,7 +199,16 @@ private static Socket Connect(string serverName, int port, TimeSpan timeout)
Socket[] sockets = new Socket[2];

CancellationTokenSource cts = new CancellationTokenSource();
cts.CancelAfter(timeout);

if (isInfiniteTimeout)
cheenamalhotra marked this conversation as resolved.
Show resolved Hide resolved
{
cts.CancelAfter(-1);
}
else
{
cts.CancelAfter(timeout);
}

void Cancel()
{
for (int i = 0; i < sockets.Length; ++i)
Expand Down