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。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(connection): raise default connect timeout
t8y27910a2f68ed7
diff --git a/apps/desktop/src/components/connection/ConnectionDialog.vue b/apps/desktop/src/components/connection/ConnectionDialog.vueindex fe5615f4c0..c5501ee423 100644--- a/apps/desktop/src/components/connection/ConnectionDialog.vue+++ b/apps/desktop/src/components/connection/ConnectionDialog.vue@@ -112,7 +112,7 @@ const defaultForm = (): ConnectionForm => ({database: undefined,color: "",transport_layers: [],- connect_timeout_secs: 5,+ connect_timeout_secs: 10,query_timeout_secs: 30,idle_timeout_secs: 60,keepalive_interval_secs: 0,@@ -720,7 +720,7 @@ watch(database: config.database,color: config.color || "",transport_layers: transportLayersForConfig(legacyConfig),- connect_timeout_secs: config.connect_timeout_secs || 5,+ connect_timeout_secs: config.connect_timeout_secs || 10,query_timeout_secs: config.query_timeout_secs ?? 30,idle_timeout_secs: config.idle_timeout_secs ?? 60,keepalive_interval_secs: config.keepalive_interval_secs ?? 0,@@ -1256,7 +1256,7 @@ function connectionConfigForSubmit(id: string): ConnectionConfig {});validateTransportLayers(config);const connectTimeout = Number(config.connect_timeout_secs);- config.connect_timeout_secs = Number.isFinite(connectTimeout) && connectTimeout > 0 ? connectTimeout : 5;+ config.connect_timeout_secs = Number.isFinite(connectTimeout) && connectTimeout > 0 ? connectTimeout : 10;const queryTimeout = Number(config.query_timeout_secs);config.query_timeout_secs = Number.isFinite(queryTimeout) && queryTimeout >= 0 ? queryTimeout : 30;const idleTimeout = Number(config.idle_timeout_secs);diff --git a/apps/desktop/src/lib/__tests__/connectionAttemptTimeout.spec.ts b/apps/desktop/src/lib/__tests__/connectionAttemptTimeout.spec.tsindex ebce369cfd..caa1667e00 100644--- a/apps/desktop/src/lib/__tests__/connectionAttemptTimeout.spec.ts+++ b/apps/desktop/src/lib/__tests__/connectionAttemptTimeout.spec.ts@@ -1,7 +1,15 @@import { describe, expect, it } from "vitest";-import { ACCESS_AGENT_MIN_CONNECT_TIMEOUT_SECS, AGENT_DRIVER_MIN_CONNECT_TIMEOUT_SECS, connectionAttemptTimeoutMs, CONNECTION_ATTEMPT_TIMEOUT_BUFFER_MS } from "@/lib/connectionAttemptTimeout";+import { ACCESS_AGENT_MIN_CONNECT_TIMEOUT_SECS, AGENT_DRIVER_MIN_CONNECT_TIMEOUT_SECS, connectionAttemptOriginalErrorMessage, connectionAttemptTimeoutMessage, connectionAttemptTimeoutMs, CONNECTION_ATTEMPT_TIMEOUT_BUFFER_MS } from "@/lib/connectionAttemptTimeout";describe("connectionAttemptTimeout", () => {+ it("uses a 10s default for regular database connections", () => {+ expect(connectionAttemptTimeoutMs({ db_type: "mysql", connect_timeout_secs: undefined, transport_layers: [] })).toBe(12_000);+ });++ it("keeps explicit regular database timeout values", () => {+ expect(connectionAttemptTimeoutMs({ db_type: "mysql", connect_timeout_secs: 5, transport_layers: [] })).toBe(7_000);+ });+it("uses a 30s agent startup floor", () => {expect(connectionAttemptTimeoutMs({ db_type: "oracle", connect_timeout_secs: 5, transport_layers: [] })).toBe(AGENT_DRIVER_MIN_CONNECT_TIMEOUT_SECS * 1000 + CONNECTION_ATTEMPT_TIMEOUT_BUFFER_MS);});@@ -13,4 +21,10 @@ describe("connectionAttemptTimeout", () => {it("respects a user configured Access timeout above the default floor", () => {expect(connectionAttemptTimeoutMs({ db_type: "access", connect_timeout_secs: 45, transport_layers: [] })).toBe(47_000);});++ it("adds late original database errors to timeout messages", () => {+ const timeoutMessage = connectionAttemptTimeoutMessage(7_000);++ expect(connectionAttemptOriginalErrorMessage(timeoutMessage, "MySQL connection failed: os error 10060")).toContain("MySQL connection failed: os error 10060");+ });});diff --git a/apps/desktop/src/lib/connectionAttemptTimeout.ts b/apps/desktop/src/lib/connectionAttemptTimeout.tsindex 4e8030df10..1b447f94a4 100644--- a/apps/desktop/src/lib/connectionAttemptTimeout.ts+++ b/apps/desktop/src/lib/connectionAttemptTimeout.ts@@ -4,7 +4,7 @@ export const CONNECTION_ATTEMPT_TIMEOUT_BUFFER_MS = 2_000;export const MONGO_LEGACY_FALLBACK_TIMEOUT_BUFFER_MS = 30_000;export const AGENT_DRIVER_MIN_CONNECT_TIMEOUT_SECS = 30;export const ACCESS_AGENT_MIN_CONNECT_TIMEOUT_SECS = 30;-const DEFAULT_CONNECT_TIMEOUT_SECS = 5;+const DEFAULT_CONNECT_TIMEOUT_SECS = 10;const AGENT_DRIVER_TYPES = new Set<DatabaseType>(["dameng",@@ -61,3 +61,9 @@ export function connectionAttemptTimeoutMs(config: Pick<ConnectionConfig, "conneexport function connectionAttemptTimeoutMessage(timeoutMs: number): string {return `Connection attempt timed out after ${Math.ceil(timeoutMs / 1000)}s. Please check the network or VPN and try again.`;}++export function connectionAttemptOriginalErrorMessage(timeoutMessage: string, originalMessage: string): string {+ const message = originalMessage.trim();+ if (!message || message === timeoutMessage) return timeoutMessage;+ return `${timeoutMessage}\n\nOriginal database error returned after the UI timeout:\n${message}`;+}diff --git a/apps/desktop/src/lib/datagripImport.ts b/apps/desktop/src/lib/datagripImport.tsindex 6a59e965f6..d7505a87f8 100644--- a/apps/desktop/src/lib/datagripImport.ts+++ b/apps/desktop/src/lib/datagripImport.ts@@ -389,7 +389,7 @@ function buildConnection(fragment: DataSourceFragment): ConnectionConfig {database,color: "",transport_layers: [],- connect_timeout_secs: 5,+ connect_timeout_secs: 10,query_timeout_secs: 30,ssl: false,oracle_connection_type: profile.dbType === "oracle" ? parsed.oracleConnectionType || "service_name" : undefined,diff --git a/apps/desktop/src/lib/dbeaverImport.ts b/apps/desktop/src/lib/dbeaverImport.tsindex 818cd9b67a..b1cc488177 100644--- a/apps/desktop/src/lib/dbeaverImport.ts+++ b/apps/desktop/src/lib/dbeaverImport.ts@@ -213,7 +213,7 @@ function buildConnection(entry: DbeaverConnectionEntry, credentials: ReturnType<database: database || undefined,color: getString(config.color || config["connection-color"]),transport_layers: [],- connect_timeout_secs: 5,+ connect_timeout_secs: 10,query_timeout_secs: 30,ssl: false,oracle_connection_type: profile.dbType === "oracle" ? parsedUrl.oracleConnectionType || "service_name" : undefined,diff --git a/apps/desktop/src/lib/navicatImport.ts b/apps/desktop/src/lib/navicatImport.tsindex 06b4c5def3..fb10dd86ca 100644--- a/apps/desktop/src/lib/navicatImport.ts+++ b/apps/desktop/src/lib/navicatImport.ts@@ -199,7 +199,7 @@ async function parseConnection(node: ParsedNode): Promise<ConnectionConfig | nuldatabase: database || undefined,color: "",transport_layers: [],- connect_timeout_secs: 5,+ connect_timeout_secs: 10,query_timeout_secs: 30,keepalive_interval_secs: keepaliveInterval,ssl: false,diff --git a/apps/desktop/src/stores/connectionStore.ts b/apps/desktop/src/stores/connectionStore.tsindex 72594b3b11..3600dbfe75 100644--- a/apps/desktop/src/stores/connectionStore.ts+++ b/apps/desktop/src/stores/connectionStore.ts@@ -27,7 +27,7 @@ import { buildDatabaseTreeNodes, buildDuckDbConnectionTreeNodes, sortSidebarNameimport { buildSqlServerDatabaseTreeNodes, SQLSERVER_DEFAULT_SCHEMA } from "@/lib/sqlServerTree";import { findDatabaseTreeNode } from "@/lib/treeRefreshTarget";import { shouldMarkDisconnected } from "@/lib/connectionHealth";-import { connectionAttemptTimeoutMessage, connectionAttemptTimeoutMs } from "@/lib/connectionAttemptTimeout";+import { connectionAttemptOriginalErrorMessage, connectionAttemptTimeoutMessage, connectionAttemptTimeoutMs } from "@/lib/connectionAttemptTimeout";import { filterDatabaseNamesForConnection, filterVisibleDatabaseNames, normalizeVisibleDatabaseSelection } from "@/lib/visibleDatabases";import {buildObjectGroupPlaceholderNodes,@@ -282,12 +282,23 @@ export const useConnectionStore = defineStore("connection", () => {async function withConnectionAttemptTimeout<T>(promise: Promise<T>, config: ConnectionConfig): Promise<T> {const timeoutMs = connectionAttemptTimeoutMs(config);+ const timeoutMessage = connectionAttemptTimeoutMessage(timeoutMs);+ let timedOut = false;let timer: ReturnType<typeof setTimeout> | undefined;+ void promise.catch((error) => {+ if (!timedOut) return;+ const current = connectionErrors.value[config.id];+ if (current !== timeoutMessage) return;+ setConnectionError(config.id, connectionAttemptOriginalErrorMessage(timeoutMessage, connectionErrorMessage(error)));+ });try {return await Promise.race([promise,new Promise<never>((_, reject) => {- timer = setTimeout(() => reject(new Error(connectionAttemptTimeoutMessage(timeoutMs))), timeoutMs);+ timer = setTimeout(() => {+ timedOut = true;+ reject(new Error(timeoutMessage));+ }, timeoutMs);}),]);} finally {@@ -366,7 +377,7 @@ export const useConnectionStore = defineStore("connection", () => {url_params: config.url_params || "",attached_databases: Array.isArray(config.attached_databases) ? config.attached_databases.filter((database) => database.name?.trim() && database.path?.trim()) : [],transport_layers: Array.isArray(config.transport_layers) ? config.transport_layers : [],- connect_timeout_secs: config.connect_timeout_secs || 5,+ connect_timeout_secs: config.connect_timeout_secs || 10,query_timeout_secs: config.query_timeout_secs ?? 30,idle_timeout_secs: config.idle_timeout_secs ?? 60,keepalive_interval_secs: config.keepalive_interval_secs ?? 0,diff --git a/crates/dbx-core/src/models/connection.rs b/crates/dbx-core/src/models/connection.rsindex c697bf9391..c78362dc88 100644--- a/crates/dbx-core/src/models/connection.rs+++ b/crates/dbx-core/src/models/connection.rs@@ -194,7 +194,7 @@ pub fn default_ssh_connect_timeout_secs() -> u64 {}pub fn default_connect_timeout_secs() -> u64 {- 5+ 10}pub fn default_query_timeout_secs() -> u64 {@@ -1581,6 +1581,24 @@ mod tests {assert!(hops[0].expose_lan);}+ #[test]+ fn missing_connection_timeout_defaults_to_ten_seconds() {+ let config: ConnectionConfig = serde_json::from_value(serde_json::json!({+ "id": "id",+ "name": "name",+ "db_type": "mysql",+ "host": "10.1.2.3",+ "port": 3306,+ "username": "root",+ "password": "",+ "database": null+ }))+ .unwrap();++ assert_eq!(config.connect_timeout_secs, 10);+ assert_eq!(config.effective_connect_timeout_secs(), 10);+ }+#[test]fn legacy_ssh_tunnels_migrate_to_ordered_transport_layers() {let config: ConnectionConfig = serde_json::from_value(serde_json::json!({diff --git a/packages/app-tests/connectionStoreErrorState.test.ts b/packages/app-tests/connectionStoreErrorState.test.tsindex 09ad8e5b26..c515aac4b6 100644--- a/packages/app-tests/connectionStoreErrorState.test.ts+++ b/packages/app-tests/connectionStoreErrorState.test.ts@@ -1,6 +1,6 @@import assert from "node:assert/strict";import { createPinia, setActivePinia } from "pinia";-import { test } from "vitest";+import { test, vi } from "vitest";import { useConnectionStore } from "../../apps/desktop/src/stores/connectionStore.ts";import type { ConnectionConfig } from "../../apps/desktop/src/types/database.ts";@@ -153,3 +153,39 @@ test("explicit lost-connection marker clears state without relying on error textrestoreStorage();}});++test("late original connect errors replace the generic timeout detail", async () => {+ vi.useFakeTimers();+ const restoreStorage = installMemoryStorage();+ const originalFetch = globalThis.fetch;+ globalThis.fetch = (async (input) => {+ if (String(input) === "/api/connection/connect") {+ return new Promise<Response>((_, reject) => {+ setTimeout(() => reject(new Error("MySQL connection failed: raw socket timeout")), 3500);+ });+ }+ return new Response("unexpected request", { status: 500 });+ }) as typeof fetch;++ try {+ setActivePinia(createPinia());+ const store = useConnectionStore();+ const config = { ...conn("conn-1"), connect_timeout_secs: 1 };+ const connectPromise = store.connect(config);+ const timeoutRejection = assert.rejects(() => connectPromise, /Connection attempt timed out after 3s/);++ await vi.advanceTimersByTimeAsync(3000);+ await timeoutRejection;+ assert.equal(store.connectionErrors["conn-1"], "Connection attempt timed out after 3s. Please check the network or VPN and try again.");++ await vi.advanceTimersByTimeAsync(500);+ await Promise.resolve();++ assert.match(store.connectionErrors["conn-1"], /Original database error returned after the UI timeout/);+ assert.match(store.connectionErrors["conn-1"], /MySQL connection failed: raw socket timeout/);+ } finally {+ vi.useRealTimers();+ globalThis.fetch = originalFetch;+ restoreStorage();+ }+});