Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(mysql): retry without ssl on TLS close

t8y2ea19a24ec664
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<MySqlPool, String> {
.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<MySqlPool, String> {
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<String> {
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));
+ }
}