From ea19a24ec6641f0abc70872d303dbbdaed4e260f Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Wed, 20 May 2026 10:42:20 +0800 Subject: [PATCH] fix(mysql): retry without ssl on TLS close --- crates/dbx-core/src/db/mysql.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/crates/dbx-core/src/db/mysql.rs b/crates/dbx-core/src/db/mysql.rs index 2237518674..3318ab2e20 100644 --- a/crates/dbx-core/src/db/mysql.rs +++ b/crates/dbx-core/src/db/mysql.rs @@ -170,7 +170,7 @@ pub async fn connect(url: &str) -> Result { .await; if let Err(ref e) = result { - if e.contains("HandshakeFailure") || e.contains("handshake") { + if mysql_error_should_retry_without_ssl(e) { if let Some(fallback_url) = ssl_fallback_url(url) { log::info!("SSL handshake failed, retrying with ssl-mode=disabled"); return super::with_connection_timeout("MySQL", async { @@ -190,6 +190,14 @@ pub async fn connect(url: &str) -> Result { result } +fn mysql_error_should_retry_without_ssl(error: &str) -> bool { + let error = error.to_ascii_lowercase(); + error.contains("handshakefailure") + || error.contains("handshake") + || error.contains("tls connection") + || error.contains("server closed session") +} + fn ssl_fallback_url(url: &str) -> Option { if url.contains("ssl-mode=preferred") { Some(url.replace("ssl-mode=preferred", "ssl-mode=disabled")) @@ -592,4 +600,13 @@ mod tests { assert!(!requires_text_protocol_query("SHOW TABLES")); assert!(!requires_text_protocol_query("SELECT * FROM users")); } + + #[test] + fn mysql_tls_session_close_errors_retry_without_ssl() { + let error = "MySQL connection failed: error communicating with database: \ + encountered error while attempting to establish a TLS connection: \ + server closed session with no notification"; + + assert!(mysql_error_should_retry_without_ssl(error)); + } }