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(connection): skip TCP probe for hostname endpoints

t8y206b0c60a0e53
diff --git a/crates/dbx-core/src/connection.rs b/crates/dbx-core/src/connection.rs
index d122fa4f50..3ba5ce439e 100644
--- a/crates/dbx-core/src/connection.rs
+++ b/crates/dbx-core/src/connection.rs
@@ -486,16 +486,16 @@ fn uses_tcp_probe(config: &ConnectionConfig, host: &str, port: u16) -> bool {
if database_capabilities::skips_tcp_probe(&config.db_type) {
return false;
}
- if matches!(config.db_type, DatabaseType::Mysql | DatabaseType::Doris | DatabaseType::StarRocks)
- && host == config.host
- && port == config.port
- && host.parse::<std::net::IpAddr>().is_err()
- {
+ if is_original_hostname_endpoint(config, host, port) {
return false;
}
true
}
+fn is_original_hostname_endpoint(config: &ConnectionConfig, host: &str, port: u16) -> bool {
+ host == config.host && port == config.port && host.parse::<std::net::IpAddr>().is_err()
+}
+
async fn detect_ob_oracle_mode(config: &ConnectionConfig, pool: &sqlx::mysql::MySqlPool) -> MysqlMode {
let profile = config.driver_profile.as_deref().unwrap_or("").to_lowercase();
if !profile.contains("oceanbase") {
@@ -675,6 +675,26 @@ mod tests {
assert!(uses_tcp_probe(&config, "127.0.0.1", 53306));
}
+ #[test]
+ fn native_hostname_connections_skip_tcp_probe() {
+ for db_type in [
+ DatabaseType::Postgres,
+ DatabaseType::Redshift,
+ DatabaseType::Redis,
+ DatabaseType::ClickHouse,
+ DatabaseType::SqlServer,
+ DatabaseType::Elasticsearch,
+ ] {
+ let mut config = mysql_config(Some("app"));
+ config.db_type = db_type;
+ config.host = "db.example.com".to_string();
+
+ assert!(!uses_tcp_probe(&config, "db.example.com", config.port), "{db_type:?} hostname");
+ assert!(uses_tcp_probe(&config, "192.0.2.10", config.port), "{db_type:?} ip");
+ assert!(uses_tcp_probe(&config, "127.0.0.1", 54000), "{db_type:?} forwarded");
+ }
+ }
+
#[tokio::test]
async fn sqlite_get_or_create_pool_initializes_connection_for_web_route() {
let (state, dir) = test_app_state().await;