@@ -340,7 +340,7 @@ public async Task ConnectAsync(ConnectionSettings cs, int startTickCount, ILoadB
340340 else if ( cs . ConnectionProtocol == MySqlConnectionProtocol . UnixSocket )
341341 connected = await OpenUnixSocketAsync ( cs , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
342342 else if ( cs . ConnectionProtocol == MySqlConnectionProtocol . NamedPipe )
343- connected = await OpenNamedPipeAsync ( cs , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
343+ connected = await OpenNamedPipeAsync ( cs , startTickCount , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
344344 if ( ! connected )
345345 {
346346 lock ( m_lock )
@@ -981,23 +981,35 @@ private async Task<bool> OpenUnixSocketAsync(ConnectionSettings cs, IOBehavior i
981981 return false ;
982982 }
983983
984- private Task < bool > OpenNamedPipeAsync ( ConnectionSettings cs , IOBehavior ioBehavior , CancellationToken cancellationToken )
984+ #if NET45 || NETSTANDARD1_3
985+ #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
986+ #endif
987+ private async Task < bool > OpenNamedPipeAsync ( ConnectionSettings cs , int startTickCount , IOBehavior ioBehavior , CancellationToken cancellationToken )
988+ #if NET45 || NETSTANDARD1_3Co
989+ #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
990+ #endif
985991 {
986992#if NETSTANDARD1_3
987993 throw new NotSupportedException( "Named pipe connections are not supported in netstandard1.3" ) ;
988994#else
989995 if ( Log . IsInfoEnabled ( ) )
990996 Log . Info ( "Session{0} connecting to NamedPipe '{1}' on Server '{2}'" , m_logArguments [ 0 ] , cs . PipeName , cs . HostNames ! [ 0 ] ) ;
991997 var namedPipeStream = new NamedPipeClientStream ( cs . HostNames ! [ 0 ] , cs . PipeName , PipeDirection . InOut , PipeOptions . Asynchronous ) ;
998+ var timeout = Math . Max ( 1 , cs . ConnectionTimeoutMilliseconds - unchecked ( Environment . TickCount - startTickCount ) ) ;
992999 try
9931000 {
9941001 using ( cancellationToken . Register ( ( ) => namedPipeStream . Dispose ( ) ) )
9951002 {
9961003 try
9971004 {
998- namedPipeStream . Connect ( ) ;
1005+ #if ! NET45
1006+ if ( ioBehavior == IOBehavior . Asynchronous )
1007+ await namedPipeStream . ConnectAsync ( timeout , cancellationToken ) . ConfigureAwait ( false ) ;
1008+ else
1009+ #endif
1010+ namedPipeStream . Connect ( timeout ) ;
9991011 }
1000- catch ( ObjectDisposedException ex ) when ( cancellationToken . IsCancellationRequested )
1012+ catch ( Exception ex ) when ( ( ex is ObjectDisposedException && cancellationToken . IsCancellationRequested ) || ex is TimeoutException )
10011013 {
10021014 m_logArguments [ 1 ] = cs . PipeName ;
10031015 Log . Info ( "Session{0} connect timeout expired connecting to named pipe '{1}'" , m_logArguments ) ;
@@ -1016,10 +1028,10 @@ private Task<bool> OpenNamedPipeAsync(ConnectionSettings cs, IOBehavior ioBehavi
10161028
10171029 lock ( m_lock )
10181030 m_state = State . Connected ;
1019- return Task . FromResult ( true ) ;
1031+ return true ;
10201032 }
10211033
1022- return Task . FromResult ( false ) ;
1034+ return false ;
10231035#endif
10241036 }
10251037
0 commit comments