@@ -426,33 +426,16 @@ private static Socket Connect(string serverName, int port, TimeoutTimer timeout,
426
426
bool isConnected ;
427
427
try // catching SocketException with SocketErrorCode == WouldBlock to run Socket.Select
428
428
{
429
- if ( isInfiniteTimeout )
429
+ socket . Connect ( ipAddress , port ) ;
430
+ if ( ! isInfiniteTimeout )
430
431
{
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
- }
448
432
throw SQL . SocketDidNotThrow ( ) ;
449
433
}
450
434
451
435
isConnected = true ;
452
436
}
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 )
456
439
{
457
440
// https://github.com/dotnet/SqlClient/issues/826#issuecomment-736224118
458
441
// 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,
509
492
return socket ;
510
493
}
511
494
}
512
- catch ( AggregateException aggregateException ) when ( aggregateException . InnerException is SocketException socketException )
495
+ catch ( SocketException e )
513
496
{
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 ) ;
515
498
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 } ") ;
517
500
}
518
501
finally
519
502
{
0 commit comments