From 82fd078c10097ca897044b1991a0c0f104a9e318 Mon Sep 17 00:00:00 2001 From: jischeng <49861575+jischeng@users.noreply.github.com> Date: Fri, 26 Jun 2026 13:16:52 +0800 Subject: [PATCH] fix(mysql): health-check pooled connection before DDL query * fix(mysql): health-check pooled connection before DDL query `mysql_ddl` fetched a connection with a raw `pool.get_conn()` and issued `SHOW CREATE TABLE` directly, unlike other read paths (`get_columns`, `list_indexes`, ...) which go through `get_conn_with_health_check`. A pooled connection that went stale while idle (server closed it after its idle timeout, NAT/firewall dropped the TCP state, ...) would then fail on the first DDL request after a period of inactivity, surfacing a low-level connection error that a manual refresh would mask. Route `mysql_ddl` through `get_conn_with_health_check` so stale connections are pinged and replaced before the query runs, matching the rest of the MySQL metadata path. * fix(test): add redis_scan_page_size to ConnectionConfig test helpers `d815a16b` (feat(redis): move scan page size to connections) added `redis_scan_page_size` to `ConnectionConfig` but did not update several struct-literal test helpers, so `cargo clippy --workspace --all-targets` fails with `missing field redis_scan_page_size`. This is a pre-existing breakage on `main` (CI has been red since that commit) and is unrelated to this PR's actual change; included here only to unblock CI. Helpers fixed here: - src-tauri/src/commands/connection.rs (`mongodb_config`) - crates/dbx-web/src/routes/connection.rs (`sqlite_config`) --- crates/dbx-core/src/schema.rs | 7 ++++++- crates/dbx-web/src/routes/connection.rs | 1 + src-tauri/src/commands/connection.rs | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/dbx-core/src/schema.rs b/crates/dbx-core/src/schema.rs index e18134991a..f46e234153 100644 --- a/crates/dbx-core/src/schema.rs +++ b/crates/dbx-core/src/schema.rs @@ -3465,7 +3465,12 @@ mod ddl_tests { pub async fn mysql_ddl(pool: &db::mysql::MySqlPool, table: &str) -> Result { use mysql_async::prelude::*; let sql = format!("SHOW CREATE TABLE `{}`", table.replace('`', "``")); - let mut conn = pool.get_conn().await.map_err(|e| e.to_string())?; + // Use the health-checked getter so a stale pooled connection (server closed + // it after an idle timeout, NAT/firewall dropped the TCP state, etc.) is + // detected and replaced before issuing the query. Without this, the first + // DDL request after a period of inactivity could surface a low-level + // connection error that a manual refresh would have masked. + let mut conn = db::mysql::get_conn_with_health_check(pool).await?; let result = conn.query_iter(&sql).await.map_err(|e| e.to_string())?; let rows: Vec = result.collect_and_drop().await.map_err(|e| e.to_string())?; let row = rows.first().ok_or("DDL not found")?; diff --git a/crates/dbx-web/src/routes/connection.rs b/crates/dbx-web/src/routes/connection.rs index 9335837f15..5a3a8c80a9 100644 --- a/crates/dbx-web/src/routes/connection.rs +++ b/crates/dbx-web/src/routes/connection.rs @@ -286,6 +286,7 @@ mod tests { redis_sentinel_tls: false, redis_cluster_nodes: String::new(), redis_key_separator: dbx_core::models::connection::default_redis_key_separator(), + redis_scan_page_size: None, etcd_endpoints: String::new(), gbase_server: String::new(), informix_server: String::new(), diff --git a/src-tauri/src/commands/connection.rs b/src-tauri/src/commands/connection.rs index ec21b7813c..6e705af38b 100644 --- a/src-tauri/src/commands/connection.rs +++ b/src-tauri/src/commands/connection.rs @@ -248,6 +248,7 @@ mod tests { redis_sentinel_tls: false, redis_cluster_nodes: String::new(), redis_key_separator: dbx_core::models::connection::default_redis_key_separator(), + redis_scan_page_size: None, etcd_endpoints: String::new(), gbase_server: String::new(), informix_server: String::new(),