From f617f0c58de4c939598d1217bf6cf1b9280dd64c Mon Sep 17 00:00:00 2001 From: Karina Zhou Date: Wed, 27 Nov 2019 15:15:49 -0800 Subject: [PATCH] Fix zero connection time issue --- .../Microsoft/Data/SqlClient/SNI/SNITcpHandle.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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)