@@ -426,33 +426,16 @@ private static Socket Connect(string serverName, int port, TimeoutTimer timeout,
426426 bool isConnected ;
427427 try // catching SocketException with SocketErrorCode == WouldBlock to run Socket.Select
428428 {
429- if ( isInfiniteTimeout )
429+ socket . Connect ( ipAddress , port ) ;
430+ if ( ! isInfiniteTimeout )
430431 {
431- socket . Connect ( ipAddress , port ) ;
432- }
433- else
434- {
435- if ( timeout . IsExpired )
436- {
437- return null ;
438- }
439- // Socket.Connect does not support infinite timeouts, so we use Task to simulate it
440- Task socketConnectTask = new Task ( ( ) => socket . Connect ( ipAddress , port ) ) ;
441- socketConnectTask . ConfigureAwait ( false ) ;
442- socketConnectTask . Start ( ) ;
443- int remainingTimeout = timeout . MillisecondsRemainingInt ;
444- if ( ! socketConnectTask . Wait ( remainingTimeout ) )
445- {
446- throw ADP . TimeoutException ( $ "The socket couldn't connect during the expected { remainingTimeout } remaining time.") ;
447- }
448432 throw SQL . SocketDidNotThrow ( ) ;
449433 }
450434
451435 isConnected = true ;
452436 }
453- catch ( AggregateException aggregateException ) when ( ! isInfiniteTimeout
454- && aggregateException . InnerException is SocketException socketException
455- && socketException . SocketErrorCode == SocketError . WouldBlock )
437+ catch ( SocketException socketException ) when ( ! isInfiniteTimeout &&
438+ socketException . SocketErrorCode == SocketError . WouldBlock )
456439 {
457440 // https://github.com/dotnet/SqlClient/issues/826#issuecomment-736224118
458441 // Socket.Select is used because it supports timeouts, while Socket.Connect does not
@@ -509,11 +492,11 @@ private static Socket Connect(string serverName, int port, TimeoutTimer timeout,
509492 return socket ;
510493 }
511494 }
512- catch ( AggregateException aggregateException ) when ( aggregateException . InnerException is SocketException socketException )
495+ catch ( SocketException e )
513496 {
514- SqlClientEventSource . Log . TrySNITraceEvent ( nameof ( SNITCPHandle ) , EventType . ERR , "THIS EXCEPTION IS BEING SWALLOWED: {0}" , args0 : socketException ? . Message ) ;
497+ SqlClientEventSource . Log . TrySNITraceEvent ( nameof ( SNITCPHandle ) , EventType . ERR , "THIS EXCEPTION IS BEING SWALLOWED: {0}" , args0 : e ? . Message ) ;
515498 SqlClientEventSource . Log . TryAdvancedTraceEvent (
516- $ "{ nameof ( SNITCPHandle ) } .{ nameof ( Connect ) } { EventType . ERR } THIS EXCEPTION IS BEING SWALLOWED: { socketException } ") ;
499+ $ "{ nameof ( SNITCPHandle ) } .{ nameof ( Connect ) } { EventType . ERR } THIS EXCEPTION IS BEING SWALLOWED: { e } ") ;
517500 }
518501 finally
519502 {
0 commit comments