diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNITcpHandle.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNITcpHandle.cs index 5f4bb63fea..cd269e5916 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNITcpHandle.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNITcpHandle.cs @@ -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) @@ -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; @@ -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) + { + cts.CancelAfter(-1); + } + else + { + cts.CancelAfter(timeout); + } + void Cancel() { for (int i = 0; i < sockets.Length; ++i)