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): swallow background querystore import rejections

zipg9aa6d9114cc3
diff --git a/apps/desktop/src/stores/__tests__/connectionStore.metadataInvalidationImport.spec.ts b/apps/desktop/src/stores/__tests__/connectionStore.metadataInvalidationImport.spec.ts
new file mode 100644
index 0000000000..5105793722
--- /dev/null
+++ b/apps/desktop/src/stores/__tests__/connectionStore.metadataInvalidationImport.spec.ts
@@ -0,0 +1,53 @@
+import { createPinia, setActivePinia } from "pinia";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import i18n from "@/i18n";
+
+function installLocalStorage() {
+ const data = new Map<string, string>();
+ vi.stubGlobal("localStorage", {
+ getItem: vi.fn((key: string) => data.get(key) ?? null),
+ setItem: vi.fn((key: string, value: string) => data.set(key, value)),
+ removeItem: vi.fn((key: string) => data.delete(key)),
+ });
+}
+
+describe("connectionStore metadata lifetime invalidation", () => {
+ beforeEach(() => {
+ vi.resetModules();
+ vi.unstubAllGlobals();
+ installLocalStorage();
+ setActivePinia(createPinia());
+ i18n.global.locale.value = "en";
+ vi.doMock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
+ vi.doMock("@/lib/backend/api", () => ({
+ checkConnectionHealth: vi.fn().mockRejectedValue(new Error("back end pool is gone")),
+ listInstalledAgents: vi.fn().mockResolvedValue([]),
+ loadSchemaCache: vi.fn().mockResolvedValue(null),
+ saveConnections: vi.fn().mockResolvedValue(undefined),
+ saveSchemaCache: vi.fn().mockResolvedValue(undefined),
+ saveSidebarLayout: vi.fn().mockResolvedValue(undefined),
+ }));
+ });
+
+ afterEach(() => {
+ vi.doUnmock("@/stores/queryStore");
+ });
+
+ it("swallows a failing deferred queryStore import instead of leaking an unhandled rejection", async () => {
+ vi.doMock("@/stores/queryStore", () => {
+ throw new Error("deferred queryStore module failed to load");
+ });
+
+ const { useConnectionStore } = await import("@/stores/connectionStore");
+ const store = useConnectionStore();
+
+ // 被动断链会以 fire-and-forget 方式(void import)清 data-tab freshness。该
+ // deferred import 失败时——CI 上表现为「环境已销毁后 chunk 才请求失败」——必须
+ // 被吞掉,否则未处理的拒绝会让整个 frontend-test 分片失败。
+ store.markConnectionLost("mssql-1", new Error("back end pool is gone"));
+
+ await vi.dynamicImportSettled();
+
+ expect(store.connectedIds.has("mssql-1")).toBe(false);
+ });
+});
diff --git a/apps/desktop/src/stores/connectionStore.ts b/apps/desktop/src/stores/connectionStore.ts
index 41151134ae..6f3d2a4bb4 100644
--- a/apps/desktop/src/stores/connectionStore.ts
+++ b/apps/desktop/src/stores/connectionStore.ts
@@ -2511,9 +2511,14 @@ export const useConnectionStore = defineStore("connection", () => {
function invalidateConnectionMetadataLifetime(connectionId: string, database?: string) {
invalidateMetadataCaches({ connectionId, database });
bumpMetadataGeneration(connectionId, database);
- void import("@/stores/queryStore").then(({ useQueryStore }) => {
- useQueryStore().staleConnectionDataTabMetadata(connectionId, database);
- });
+ // 该 import 是「稍后清理 freshness」的尽力而为路径:断开连接后数据标签页的
+ // tableMeta 不再算 warm cache,晚一点清也安全。因此这里必须吞掉失败,避免
+ // chunk 加载失败(或测试环境已销毁)变成未处理的拒绝。
+ void import("@/stores/queryStore")
+ .then(({ useQueryStore }) => {
+ useQueryStore().staleConnectionDataTabMetadata(connectionId, database);
+ })
+ .catch(() => undefined);
}
function invalidateMetadataCaches(match: MetadataCacheInvalidation): number {