diff --git a/crates/dbx-core/src/db/mysql.rs b/crates/dbx-core/src/db/mysql.rs index d11860d126..2411af113d 100644 --- a/crates/dbx-core/src/db/mysql.rs +++ b/crates/dbx-core/src/db/mysql.rs @@ -155,13 +155,16 @@ fn mysql_value_to_json(row: &MySqlRow, idx: usize, type_name: &str) -> serde_jso } pub async fn connect(url: &str) -> Result { - MySqlPoolOptions::new() - .max_connections(5) - .acquire_timeout(Duration::from_secs(10)) - .idle_timeout(Duration::from_secs(300)) - .connect(url) - .await - .map_err(|e| format!("MySQL connection failed: {e}")) + super::with_connection_timeout("MySQL", async { + MySqlPoolOptions::new() + .max_connections(5) + .acquire_timeout(super::connection_timeout()) + .idle_timeout(Duration::from_secs(300)) + .connect(url) + .await + .map_err(|e| format!("MySQL connection failed: {e}")) + }) + .await } pub async fn connect_bare(url: &str) -> Result { @@ -172,13 +175,16 @@ pub async fn connect_bare(url: &str) -> Result { .set_names(false) .pipes_as_concat(false) .timezone(None); - MySqlPoolOptions::new() - .max_connections(5) - .acquire_timeout(Duration::from_secs(10)) - .idle_timeout(Duration::from_secs(300)) - .connect_with(options) - .await - .map_err(|e| format!("MySQL connection failed: {e}")) + super::with_connection_timeout("MySQL", async { + MySqlPoolOptions::new() + .max_connections(5) + .acquire_timeout(super::connection_timeout()) + .idle_timeout(Duration::from_secs(300)) + .connect_with(options) + .await + .map_err(|e| format!("MySQL connection failed: {e}")) + }) + .await } pub async fn list_databases(pool: &MySqlPool) -> Result, String> { diff --git a/crates/dbx-core/src/db/postgres.rs b/crates/dbx-core/src/db/postgres.rs index f0fe60a590..f0a779a111 100644 --- a/crates/dbx-core/src/db/postgres.rs +++ b/crates/dbx-core/src/db/postgres.rs @@ -92,13 +92,16 @@ pub async fn connect(url: &str) -> Result { // Validate SSL certificate paths if present in the URL validate_postgres_ssl_paths(url)?; - PgPoolOptions::new() - .max_connections(5) - .acquire_timeout(Duration::from_secs(10)) - .idle_timeout(Duration::from_secs(300)) - .connect(url) - .await - .map_err(|e| format!("PostgreSQL connection failed: {e}")) + super::with_connection_timeout("PostgreSQL", async { + PgPoolOptions::new() + .max_connections(5) + .acquire_timeout(super::connection_timeout()) + .idle_timeout(Duration::from_secs(300)) + .connect(url) + .await + .map_err(|e| format!("PostgreSQL connection failed: {e}")) + }) + .await } /// Validates SSL certificate file paths in PostgreSQL connection URLs. diff --git a/crates/dbx-core/src/db/redis_driver.rs b/crates/dbx-core/src/db/redis_driver.rs index f0dd1b03b2..fd7c750e7b 100644 --- a/crates/dbx-core/src/db/redis_driver.rs +++ b/crates/dbx-core/src/db/redis_driver.rs @@ -28,17 +28,20 @@ pub struct RedisValue { pub async fn connect(url: &str) -> Result { let client = redis::Client::open(url).map_err(|e| format!("Redis connection failed: {e}"))?; let mut con = tokio::time::timeout( - std::time::Duration::from_secs(10), + super::connection_timeout(), client.get_multiplexed_async_connection(), ) .await - .map_err(|_| "Redis connection timed out (10s)".to_string())? + .map_err(|_| format!("Redis connection timed out ({}s)", super::CONNECTION_TIMEOUT_SECS))? .map_err(|e| format!("Redis connection failed: {e}"))?; - redis::cmd("PING") - .query_async::(&mut con) - .await - .map_err(|e| format!("Redis authentication failed or command rejected: {e}"))?; + tokio::time::timeout( + super::connection_timeout(), + redis::cmd("PING").query_async::(&mut con), + ) + .await + .map_err(|_| format!("Redis ping timed out ({}s)", super::CONNECTION_TIMEOUT_SECS))? + .map_err(|e| format!("Redis authentication failed or command rejected: {e}"))?; Ok(con) }