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): keep pool when health probe times out during export

zipg425ca055ea2a
diff --git a/crates/dbx-core/src/connection.rs b/crates/dbx-core/src/connection.rs
index 5f4233fd56..d7fb973321 100644
--- a/crates/dbx-core/src/connection.rs
+++ b/crates/dbx-core/src/connection.rs
@@ -3352,10 +3352,14 @@ impl AppState {
checked_mysql_pool = Some(pool.clone());
drop(connections);
match db::mysql::checkout_mysql_conn(&pool, HEALTH_CHECK_POOL_ACQUIRE_TIMEOUT).await {
- // Pool saturation means active work, not a dead connection. Removing this pool would
- // start a competing reconnect while foreground queries and metadata are still running.
- Err(err) if err.is_pool_saturation() => {
- log::debug!("MySQL connection pool '{pool_key}' is busy; skipping health probe: {err}");
+ // The 500 ms probe budget is intentionally shorter than a foreground checkout. A timeout
+ // while waiting, creating, or recycling is inconclusive: slow remote handshakes and active
+ // metadata exports can legitimately exceed it. Removing the pool here would start competing
+ // reconnects while useful work is still running.
+ Err(err @ db::PoolCheckoutError::Timeout { .. }) => {
+ log::debug!(
+ "MySQL connection pool '{pool_key}' did not finish a health checkout; keeping pool: {err}"
+ );
false
}
Err(err) => {
@@ -7005,6 +7009,40 @@ mod tests {
let _ = std::fs::remove_dir_all(dir);
}
+ #[tokio::test]
+ async fn mysql_health_check_keeps_pool_when_connection_creation_exceeds_probe_budget() {
+ let listener = tokio::net::TcpListener::bind(("127.0.0.1", 0)).await.unwrap();
+ let address = listener.local_addr().unwrap();
+ let server = tokio::spawn(async move {
+ let (_socket, _) = listener.accept().await.unwrap();
+ std::future::pending::<()>().await;
+ });
+ let pool_options =
+ mysql_async::PoolOpts::new().with_constraints(mysql_async::PoolConstraints::new(1, 2).unwrap());
+ let options = mysql_async::OptsBuilder::default()
+ .ip_or_hostname(address.ip().to_string())
+ .tcp_port(address.port())
+ .user(Some("fault-injection"))
+ .pass(Some("fault-injection"))
+ .pool_opts(Some(pool_options));
+ let pool = db::mysql::MySqlPool::new(options, 2);
+ let (state, dir) = test_app_state().await;
+ state.connections.write().await.insert("conn".to_string(), PoolKind::Mysql(pool.clone(), MysqlMode::Normal));
+
+ let started = Instant::now();
+ assert!(!state.remove_stale_connection_pool("conn").await);
+
+ assert!(started.elapsed() >= super::HEALTH_CHECK_POOL_ACQUIRE_TIMEOUT);
+ assert!(matches!(
+ state.connections.read().await.get("conn"),
+ Some(PoolKind::Mysql(current, _)) if pool.is_same_pool(current)
+ ));
+ state.connections.write().await.remove("conn");
+ server.abort();
+ let _ = tokio::time::timeout(Duration::from_secs(1), pool.disconnect()).await;
+ let _ = std::fs::remove_dir_all(dir);
+ }
+
#[tokio::test]
async fn jdbc_plugin_env_uses_managed_jre_when_installed() {
let dir = std::env::temp_dir().join(format!("dbx-core-jdbc-managed-jre-{}", uuid::Uuid::new_v4()));