Skip to content

Commit d89918c

Browse files
committed
Avoid retrying TLS when a non-recoverable exception occurs.
Certain types of IOException will not be resolved by retrying the connection with a different TLS version so we can avoid the loop and throw the exception immediately.
1 parent e39d3b8 commit d89918c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/MySqlConnector/Core/ServerSession.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,13 +549,16 @@ public async Task DisposeAsync(IOBehavior ioBehavior, CancellationToken cancella
549549
Log.SessionDoesNotSupportSslProtocolsNone(m_logger, ex, Id);
550550
sslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12;
551551
}
552-
catch (Exception ex) when (shouldRetrySsl && ((ex is MySqlException && ex.InnerException is AuthenticationException or IOException) || ex is AuthenticationException or IOException))
552+
catch (Exception ex) when (shouldRetrySsl && IsRetryableException(ex))
553553
{
554554
// negotiating TLS 1.2 with a yaSSL-based server throws an exception on Windows, see comment at top of method
555555
Log.FailedNegotiatingTls(m_logger, ex, Id);
556556
sslProtocols = sslProtocols == SslProtocols.None ? SslProtocols.Tls | SslProtocols.Tls11 : (SslProtocols.Tls | SslProtocols.Tls11) & sslProtocols;
557557
shouldUpdatePoolSslProtocols = true;
558558
}
559+
560+
static bool IsRetryableException(Exception? ex) => (ex is MySqlException && IsRetryableException(ex.InnerException)) ||
561+
(ex is AuthenticationException or (IOException and not FileNotFoundException and not DirectoryNotFoundException and not DriveNotFoundException and not PathTooLongException));
559562
}
560563
else
561564
{

0 commit comments

Comments
 (0)