fix(vastbase): support old passwords and retire stale connections
Closes #8481
This commit is contained in:
1 parent
f75f5eb159
commit
92da1bcbee
19 files changed
+730
-32
No files matched your search
@@ -0,0 +1,272 @@
|
||||
import { createPinia, setActivePinia } from "pinia";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { ConnectionConfig } from "@/types/database";
|
||||
|
||||
const api = vi.hoisted(() => ({
|
||||
connectDb: vi.fn(),
|
||||
disconnectDb: vi.fn(),
|
||||
saveConnections: vi.fn(),
|
||||
sessionCredentialStatus: vi.fn(),
|
||||
forgetSessionCredential: vi.fn(),
|
||||
checkConnectionHealth: vi.fn(),
|
||||
connectionIdentifierQuote: vi.fn(),
|
||||
}));
|
||||
const requestPassword = vi.hoisted(() => vi.fn());
|
||||
const retainedTabRefresh = vi.hoisted(() => vi.fn());
|
||||
|
||||
vi.mock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
|
||||
vi.mock("@/lib/backend/api", () => ({
|
||||
...api,
|
||||
deleteSchemaCachePrefix: vi.fn().mockResolvedValue(undefined),
|
||||
loadSchemaCache: vi.fn().mockResolvedValue(null),
|
||||
saveSidebarLayout: vi.fn().mockResolvedValue(undefined),
|
||||
connectionDatabaseInfo: vi.fn().mockResolvedValue(undefined),
|
||||
listInstalledAgents: vi.fn().mockResolvedValue([]),
|
||||
}));
|
||||
vi.mock("@/stores/connectionPasswordPromptStore", () => ({
|
||||
useConnectionPasswordPromptStore: () => ({ pending: null, requestPassword }),
|
||||
}));
|
||||
vi.mock("@/stores/queryStore", () => ({
|
||||
useQueryStore: () => ({
|
||||
rollbackConnectionTransactions: retainedTabRefresh,
|
||||
closeConnectionTabs: retainedTabRefresh,
|
||||
releaseConnectionTabs: retainedTabRefresh,
|
||||
invalidateConnectionMetadata: vi.fn(),
|
||||
tabs: [],
|
||||
flushPendingPersist: vi.fn().mockResolvedValue(undefined),
|
||||
}),
|
||||
}));
|
||||
|
||||
const config: ConnectionConfig = {
|
||||
id: "vastbase-password-fixture",
|
||||
name: "Vastbase fixture",
|
||||
db_type: "vastbase",
|
||||
host: "localhost",
|
||||
port: 5432,
|
||||
username: "fixture_self",
|
||||
password: "fixture-old",
|
||||
save_password: true,
|
||||
};
|
||||
|
||||
function deferred<T>() {
|
||||
let resolve!: (value: T) => void;
|
||||
const promise = new Promise<T>((complete) => {
|
||||
resolve = complete;
|
||||
});
|
||||
return { promise, resolve };
|
||||
}
|
||||
|
||||
describe("connectionStore password retirement", () => {
|
||||
beforeEach(() => {
|
||||
const data = new Map<string, string>();
|
||||
vi.stubGlobal("localStorage", {
|
||||
getItem: (key: string) => data.get(key) ?? null,
|
||||
setItem: (key: string, value: string) => data.set(key, value),
|
||||
removeItem: (key: string) => data.delete(key),
|
||||
});
|
||||
setActivePinia(createPinia());
|
||||
for (const mock of Object.values(api)) mock.mockReset().mockResolvedValue(undefined);
|
||||
api.connectDb.mockResolvedValue(config.id);
|
||||
api.sessionCredentialStatus.mockResolvedValue(true);
|
||||
retainedTabRefresh.mockReset();
|
||||
requestPassword.mockReset().mockResolvedValue({ password: "fixture-new", rememberPassword: false });
|
||||
});
|
||||
|
||||
afterEach(() => vi.unstubAllGlobals());
|
||||
|
||||
async function storeWithConnection() {
|
||||
const { useConnectionStore } = await import("@/stores/connectionStore");
|
||||
const { useSettingsStore } = await import("@/stores/settingsStore");
|
||||
useSettingsStore().editorSettings.disconnectTabHandlingMode = "keep-tabs-keep-results";
|
||||
const store = useConnectionStore();
|
||||
store.connections = [{ ...config }, { ...config, id: "other-connection", password: "other-secret" }];
|
||||
store.connectedIds.add(config.id);
|
||||
return store;
|
||||
}
|
||||
|
||||
it("blocks retained-tab reconnects before disconnect and clears only the changed connection", async () => {
|
||||
const store = await storeWithConnection();
|
||||
let finishDisconnect!: () => void;
|
||||
api.disconnectDb.mockImplementation(
|
||||
() =>
|
||||
new Promise<void>((resolve) => {
|
||||
finishDisconnect = resolve;
|
||||
}),
|
||||
);
|
||||
const retirement = store.retirePasswordAfterChange(config.id);
|
||||
await expect(store.ensureConnected(config.id)).rejects.toThrow();
|
||||
await expect(store.connect(config)).rejects.toThrow();
|
||||
let retainedTabError: unknown;
|
||||
retainedTabRefresh.mockImplementation(() => {
|
||||
void store.ensureConnected(config.id).catch((error) => {
|
||||
retainedTabError = error;
|
||||
});
|
||||
});
|
||||
await vi.waitFor(() => expect(retainedTabRefresh).toHaveBeenCalled());
|
||||
finishDisconnect();
|
||||
await retirement;
|
||||
expect(retainedTabError).toBeInstanceOf(Error);
|
||||
expect(api.connectDb).not.toHaveBeenCalled();
|
||||
expect(api.checkConnectionHealth).not.toHaveBeenCalled();
|
||||
expect(api.forgetSessionCredential).toHaveBeenCalledWith(config.id);
|
||||
expect(api.disconnectDb.mock.invocationCallOrder[0]).toBeLessThan(api.forgetSessionCredential.mock.invocationCallOrder[0]);
|
||||
expect(store.getConfig(config.id)).toMatchObject({ password: "", save_password: false });
|
||||
expect(store.getConfig("other-connection")?.password).toBe("other-secret");
|
||||
expect(api.saveConnections).toHaveBeenCalledWith(expect.arrayContaining([expect.objectContaining({ id: config.id, password: "", save_password: false })]));
|
||||
await expect(store.ensureConnected(config.id, { forceReconnect: true })).rejects.toThrow();
|
||||
});
|
||||
|
||||
it("requires fresh input for explicit reconnect even if a caller retains the old config", async () => {
|
||||
const store = await storeWithConnection();
|
||||
await store.retirePasswordAfterChange(config.id);
|
||||
await store.connect(config);
|
||||
expect(requestPassword).toHaveBeenCalledTimes(1);
|
||||
expect(api.connectDb).toHaveBeenCalledWith(expect.objectContaining({ password: "fixture-new", save_password: false }), expect.any(Number));
|
||||
expect(store.getConfig(config.id)?.password).toBe("");
|
||||
await expect(store.ensureConnected(config.id, { verifyHealth: false })).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
describe.each(["connect", "ensureConnected"] as const)("%s credential persistence", (method) => {
|
||||
it.each(["none", "transient", "remembered"] as const)("does not restore a retired password after a delayed save with %s fresh reconnect", async (reconnect) => {
|
||||
const store = await storeWithConnection();
|
||||
const unsaved = { ...config, password: "", save_password: false };
|
||||
store.connections[0] = unsaved;
|
||||
store.connectedIds.delete(config.id);
|
||||
store.connectedIds.add("other-connection");
|
||||
const other = { ...store.getConfig("other-connection")! };
|
||||
const oldSave = deferred<void>();
|
||||
const oldSaveEntered = deferred<void>();
|
||||
let persisted = store.connections.map((connection) => ({ ...connection }));
|
||||
api.saveConnections.mockImplementation(async (snapshot: ConnectionConfig[]) => {
|
||||
const saved = snapshot.map((connection) => ({ ...connection }));
|
||||
if (saved.find((connection) => connection.id === config.id)?.password === config.password) {
|
||||
oldSaveEntered.resolve();
|
||||
await oldSave.promise;
|
||||
}
|
||||
persisted = saved;
|
||||
});
|
||||
api.sessionCredentialStatus.mockResolvedValue(false);
|
||||
requestPassword.mockResolvedValueOnce({ password: config.password, rememberPassword: true });
|
||||
|
||||
const connecting = (method === "connect" ? store.connect(unsaved) : store.ensureConnected(config.id)).catch((error: unknown) => error);
|
||||
await oldSaveEntered.promise;
|
||||
const waiting = method === "ensureConnected" ? store.ensureConnected(config.id, { forceReconnect: true }).catch((error: unknown) => error) : undefined;
|
||||
expect(store.connectedIds.has(config.id)).toBe(true);
|
||||
await store.retirePasswordAfterChange(config.id);
|
||||
expect(store.getConfig(config.id)).toMatchObject({ password: "", save_password: false });
|
||||
expect(persisted.find((connection) => connection.id === config.id)).toMatchObject({ password: "", save_password: false });
|
||||
|
||||
if (reconnect !== "none") {
|
||||
requestPassword.mockResolvedValueOnce({ password: "fixture-new", rememberPassword: reconnect === "remembered" });
|
||||
await store.connect(unsaved);
|
||||
expect(api.connectDb).toHaveBeenLastCalledWith(expect.objectContaining({ password: "fixture-new" }), expect.any(Number));
|
||||
}
|
||||
const current = store.connections.map((connection) => ({ ...connection }));
|
||||
const active = store.activeConnectionId;
|
||||
const currentError = store.connectionErrors[config.id];
|
||||
const disconnectCount = api.disconnectDb.mock.calls.length;
|
||||
oldSave.resolve();
|
||||
const result = await connecting;
|
||||
const waitingResult = await waiting;
|
||||
|
||||
expect.soft(store.connections).toEqual(current);
|
||||
expect.soft(persisted).toEqual(current);
|
||||
expect(api.saveConnections).toHaveBeenCalledTimes(reconnect === "remembered" ? 4 : 3);
|
||||
expect(store.connectedIds.has(config.id)).toBe(reconnect !== "none");
|
||||
expect(store.activeConnectionId).toBe(active);
|
||||
expect(store.connectionErrors[config.id]).toBe(currentError);
|
||||
expect(api.disconnectDb).toHaveBeenCalledTimes(disconnectCount);
|
||||
expect(store.getConfig("other-connection")).toEqual(other);
|
||||
expect(store.connectedIds.has("other-connection")).toBe(true);
|
||||
expect(persisted.find((connection) => connection.id === "other-connection")).toEqual(other);
|
||||
expect(result).toBeInstanceOf(Error);
|
||||
if (waiting) expect(waitingResult).toBeInstanceOf(Error);
|
||||
if (reconnect === "none") await expect(store.ensureConnected(config.id)).rejects.toThrow();
|
||||
else await expect(store.ensureConnected(config.id, { verifyHealth: false })).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it.each([false, true])("does not save a retired password after metadata resumes (fresh reconnect: %s)", async (reconnect) => {
|
||||
const store = await storeWithConnection();
|
||||
const unsaved = { ...config, db_type: "gaussdb" as const, password: "", save_password: false };
|
||||
store.connections[0] = unsaved;
|
||||
store.connectedIds.delete(config.id);
|
||||
const metadata = deferred<string>();
|
||||
const metadataEntered = deferred<void>();
|
||||
api.connectionIdentifierQuote.mockImplementationOnce(() => {
|
||||
metadataEntered.resolve();
|
||||
return metadata.promise;
|
||||
});
|
||||
api.sessionCredentialStatus.mockResolvedValue(false);
|
||||
requestPassword.mockResolvedValueOnce({ password: config.password, rememberPassword: true });
|
||||
|
||||
const connecting = (method === "connect" ? store.connect(unsaved) : store.ensureConnected(config.id)).catch((error: unknown) => error);
|
||||
await metadataEntered.promise;
|
||||
expect(store.connectedIds.has(config.id)).toBe(true);
|
||||
expect(api.saveConnections).not.toHaveBeenCalled();
|
||||
await store.retirePasswordAfterChange(config.id);
|
||||
if (reconnect) await store.connect(unsaved);
|
||||
const current = store.connections.map((connection) => ({ ...connection }));
|
||||
const active = store.activeConnectionId;
|
||||
const currentError = store.connectionErrors[config.id];
|
||||
metadata.resolve('"');
|
||||
const result = await connecting;
|
||||
|
||||
expect(store.connections).toEqual(current);
|
||||
expect(api.saveConnections).toHaveBeenCalledTimes(1);
|
||||
expect(api.saveConnections).toHaveBeenLastCalledWith(current);
|
||||
expect(store.connectedIds.has(config.id)).toBe(reconnect);
|
||||
expect(store.activeConnectionId).toBe(active);
|
||||
expect(store.connectionErrors[config.id]).toBe(currentError);
|
||||
expect(api.disconnectDb).toHaveBeenCalledTimes(1);
|
||||
expect(result).toBeInstanceOf(Error);
|
||||
});
|
||||
});
|
||||
|
||||
it.each(["connect", "ensureConnected"] as const)("cancels %s already waiting on a previous disconnect", async (method) => {
|
||||
const store = await storeWithConnection();
|
||||
let finishDisconnect!: () => void;
|
||||
api.disconnectDb.mockImplementationOnce(
|
||||
() =>
|
||||
new Promise<void>((resolve) => {
|
||||
finishDisconnect = resolve;
|
||||
}),
|
||||
);
|
||||
const disconnect = store.disconnect(config.id);
|
||||
const pendingConnect = (method === "connect" ? store.connect(config) : store.ensureConnected(config.id)).catch((error: unknown) => error);
|
||||
const retirement = store.retirePasswordAfterChange(config.id);
|
||||
finishDisconnect();
|
||||
await Promise.all([disconnect, retirement]);
|
||||
expect(await pendingConnect).toBeInstanceOf(Error);
|
||||
expect(api.connectDb).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("keeps automatic reconnect blocked when fresh input is cancelled or rejected", async () => {
|
||||
const store = await storeWithConnection();
|
||||
await store.retirePasswordAfterChange(config.id);
|
||||
requestPassword.mockResolvedValueOnce(null);
|
||||
await expect(store.connect(config)).rejects.toThrow();
|
||||
expect(api.connectDb).not.toHaveBeenCalled();
|
||||
api.connectDb.mockRejectedValueOnce(new Error("server rejected new password"));
|
||||
await expect(store.connect(config)).rejects.toThrow("server rejected new password");
|
||||
await expect(store.ensureConnected(config.id)).rejects.toThrow();
|
||||
expect(store.getConfig(config.id)?.password).toBe("");
|
||||
});
|
||||
|
||||
it.each(["saveConnections", "disconnectDb", "sessionCredentialStatus", "forgetSessionCredential"] as const)("stays blocked if %s fails after the server changed the password", async (method) => {
|
||||
const store = await storeWithConnection();
|
||||
api[method].mockRejectedValueOnce(new Error("fixture cleanup failure"));
|
||||
await expect(store.retirePasswordAfterChange(config.id)).rejects.toThrow();
|
||||
await expect(store.ensureConnected(config.id)).rejects.toThrow();
|
||||
await expect(store.connect(config)).rejects.toThrow();
|
||||
expect(api.connectDb).not.toHaveBeenCalled();
|
||||
expect(store.getConfig(config.id)?.password).toBe("");
|
||||
});
|
||||
|
||||
it("does not forget a nonexistent transient password for a saved-password connection", async () => {
|
||||
const store = await storeWithConnection();
|
||||
api.sessionCredentialStatus.mockResolvedValue(false);
|
||||
await store.retirePasswordAfterChange(config.id);
|
||||
expect(api.forgetSessionCredential).not.toHaveBeenCalled();
|
||||
expect(store.connectedIds.has(config.id)).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -683,6 +683,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
const connectInFlight = new Map<string, Promise<void>>();
|
||||
const disconnectInFlight = new Map<string, Promise<void>>();
|
||||
const disconnectInFlightScoped = new Map<string, boolean>();
|
||||
const passwordChangeReconnectRequired = new Map<string, "retiring" | "ready">();
|
||||
const cancelDisconnectInFlight = new Map<string, Promise<void>>();
|
||||
const activeLocalConnectionAttempts = new Map<string, number>();
|
||||
const cancelledLocalConnectionAttempts = new Map<string, Set<number>>();
|
||||
@@ -4536,15 +4537,16 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
}
|
||||
}
|
||||
|
||||
async function persistRememberedConnectionPassword(config: ConnectionConfig, rememberPassword: boolean, expectedConfigFingerprint: string): Promise<void> {
|
||||
if (!rememberPassword) return;
|
||||
async function persistRememberedConnectionPassword(config: ConnectionConfig, rememberPassword: boolean, expectedConfigFingerprint: string, localAttempt: number): Promise<void> {
|
||||
if (!rememberPassword || !isCurrentLocalConnectionAttempt(config.id, localAttempt)) return;
|
||||
const index = connections.value.findIndex((connection) => connection.id === config.id);
|
||||
if (index < 0) return;
|
||||
if (connectionConfigFingerprint(connections.value[index]) !== expectedConfigFingerprint) return;
|
||||
const nextConnections = [...connections.value];
|
||||
nextConnections[index] = { ...nextConnections[index], password: config.password, save_password: true };
|
||||
await persistConnections(nextConnections);
|
||||
if (connectionConfigFingerprint(connections.value[index]) !== expectedConfigFingerprint) {
|
||||
const current = getConfig(config.id);
|
||||
if (!isCurrentLocalConnectionAttempt(config.id, localAttempt) || !current || connectionConfigFingerprint(current) !== expectedConfigFingerprint) {
|
||||
await persistConnections();
|
||||
return;
|
||||
}
|
||||
@@ -4569,12 +4571,19 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
|
||||
async function connect(config: ConnectionConfig) {
|
||||
config = normalizeConnection(config);
|
||||
const passwordChangeState = passwordChangeReconnectRequired.get(config.id);
|
||||
if (passwordChangeState === "retiring") throw new Error(i18n.global.t("userAdmin.passwordChangedCleanupFailed"));
|
||||
const expectedConfigFingerprint = connectionConfigFingerprint(getConfig(config.id) ?? config);
|
||||
if (getBlockingDisconnectInFlight(config.id)) await waitForBlockingDisconnectInFlight(config.id);
|
||||
if (passwordChangeReconnectRequired.get(config.id) !== passwordChangeState) throw new Error(i18n.global.t("userAdmin.passwordChangedReconnect"));
|
||||
const localAttempt = beginLocalConnectionAttempt(config.id);
|
||||
try {
|
||||
let rememberPassword = false;
|
||||
if (connectionNeedsPasswordPrompt(config) && (await pluginConnectionPasswordPromptNeeded(config)) && !(await hasSessionCredential(config.id))) {
|
||||
if (passwordChangeState === "ready") {
|
||||
const prompted = await ensureConnectionPassword({ ...config, password: "", save_password: false }, true);
|
||||
config = prompted.config;
|
||||
rememberPassword = prompted.rememberPassword;
|
||||
} else if (connectionNeedsPasswordPrompt(config) && (await pluginConnectionPasswordPromptNeeded(config)) && !(await hasSessionCredential(config.id))) {
|
||||
const prompted = await ensureConnectionPassword(config);
|
||||
config = prompted.config;
|
||||
rememberPassword = prompted.rememberPassword;
|
||||
@@ -4591,11 +4600,13 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
await ensureLocalConnectionAttemptActiveAfterConnectResult(config.id, localAttempt, id);
|
||||
await syncMongoLegacyDriverFallback(id, config);
|
||||
await ensureLocalConnectionAttemptActiveAfterConnectResult(config.id, localAttempt, id);
|
||||
passwordChangeReconnectRequired.delete(config.id);
|
||||
activeConnectionId.value = id;
|
||||
connectedIds.value.add(id);
|
||||
if (config.db_type !== "plugin") {
|
||||
void refreshConnectedDatabaseInfo(id, { ...config, id });
|
||||
await refreshConnectionIdentifierQuote(id, { ...config, id });
|
||||
ensureLocalConnectionAttemptActive(config.id, localAttempt);
|
||||
// Compatibility modes warm asynchronously; the QueryEditor watcher and the
|
||||
// backend's own A-mode/EXISTS validation make a cold map safe.
|
||||
void refreshConnectionDatabaseModes(id, { ...config, id });
|
||||
@@ -4627,18 +4638,18 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
});
|
||||
}
|
||||
try {
|
||||
await persistRememberedConnectionPassword(config, rememberPassword, expectedConfigFingerprint);
|
||||
await persistRememberedConnectionPassword(config, rememberPassword, expectedConfigFingerprint, localAttempt);
|
||||
} catch (error) {
|
||||
setConnectionError(id, i18n.global.t("connection.rememberPasswordSaveFailed", { message: connectionErrorMessage(error) }));
|
||||
if (isCurrentLocalConnectionAttempt(config.id, localAttempt)) setConnectionError(id, i18n.global.t("connection.rememberPasswordSaveFailed", { message: connectionErrorMessage(error) }));
|
||||
}
|
||||
ensureLocalConnectionAttemptActive(config.id, localAttempt);
|
||||
return id;
|
||||
} catch (e) {
|
||||
if (isCancelledLocalConnectionAttempt(config.id, localAttempt)) {
|
||||
clearConnectionError(config.id);
|
||||
throw new Error(CONNECTION_ATTEMPT_CANCELLED_MESSAGE);
|
||||
}
|
||||
if (isCancelledConnectionAttempt(e) || isSupersededConnectionAttempt(e)) {
|
||||
clearConnectionError(config.id);
|
||||
if (isCurrentLocalConnectionAttempt(config.id, localAttempt)) clearConnectionError(config.id);
|
||||
} else {
|
||||
recordConnectionError(config.id, e);
|
||||
}
|
||||
@@ -4824,6 +4835,21 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
await api.forgetSessionCredential(connectionId);
|
||||
}
|
||||
|
||||
async function retirePasswordAfterChange(connectionId: string) {
|
||||
passwordChangeReconnectRequired.set(connectionId, "retiring");
|
||||
connections.value = connections.value.map((config) => (config.id === connectionId ? { ...config, password: "", save_password: false } : config));
|
||||
const results = await Promise.allSettled([disconnect(connectionId), persistConnections()]);
|
||||
try {
|
||||
if (await api.sessionCredentialStatus(connectionId)) await api.forgetSessionCredential(connectionId);
|
||||
if (results.some((result) => result.status === "rejected")) throw new Error();
|
||||
passwordChangeReconnectRequired.set(connectionId, "ready");
|
||||
setConnectionError(connectionId, i18n.global.t("userAdmin.passwordChangedReconnect"));
|
||||
} catch {
|
||||
setConnectionError(connectionId, i18n.global.t("userAdmin.passwordChangedCleanupFailed"));
|
||||
throw new Error(i18n.global.t("userAdmin.passwordChangedCleanupFailed"));
|
||||
}
|
||||
}
|
||||
|
||||
async function closeDatabaseConnection(connectionId: string, database: string) {
|
||||
if (hasSqlServerActivityTraceForConnection(connectionId, database)) await disposeSqlServerActivityTracesForConnection(connectionId, database);
|
||||
cancelObjectDdlLoadsForDatabase(connectionId, database);
|
||||
@@ -4863,6 +4889,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
}
|
||||
|
||||
async function ensureConnected(connectionId: string, options: { activate?: boolean; verifyHealth?: boolean; forceReconnect?: boolean; allowPasswordPrompt?: boolean } = {}) {
|
||||
if (passwordChangeReconnectRequired.has(connectionId)) throw new Error(i18n.global.t("userAdmin.passwordChangedReconnect"));
|
||||
if (!options.forceReconnect && connectedIds.value.has(connectionId)) {
|
||||
// Pure navigation can safely trust the existing connected state. Its
|
||||
// destination will perform the real API request, while blocking here on
|
||||
@@ -4906,6 +4933,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
}
|
||||
const expectedConfigFingerprint = connectionConfigFingerprint(config);
|
||||
if (getBlockingDisconnectInFlight(connectionId)) await waitForBlockingDisconnectInFlight(connectionId);
|
||||
if (passwordChangeReconnectRequired.has(connectionId)) throw new Error(i18n.global.t("userAdmin.passwordChangedReconnect"));
|
||||
const existingConnect = connectInFlight.get(connectionId);
|
||||
if (existingConnect) {
|
||||
await existingConnect;
|
||||
@@ -4940,32 +4968,33 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
if (config.db_type !== "plugin") {
|
||||
void refreshConnectedDatabaseInfo(connectionId, config);
|
||||
await refreshConnectionIdentifierQuote(connectionId, config);
|
||||
ensureLocalConnectionAttemptActive(connectionId, localAttempt);
|
||||
void refreshConnectionDatabaseModes(connectionId, config);
|
||||
}
|
||||
markSuccessfulLocalConnectionAttempt(connectionId, localAttempt);
|
||||
markConnectionHealthChecked(connectionId);
|
||||
clearConnectionError(connectionId);
|
||||
try {
|
||||
await persistRememberedConnectionPassword(config, rememberPassword, expectedConfigFingerprint);
|
||||
await persistRememberedConnectionPassword(config, rememberPassword, expectedConfigFingerprint, localAttempt);
|
||||
} catch (error) {
|
||||
setConnectionError(connectionId, i18n.global.t("connection.rememberPasswordSaveFailed", { message: connectionErrorMessage(error) }));
|
||||
if (isCurrentLocalConnectionAttempt(connectionId, localAttempt)) setConnectionError(connectionId, i18n.global.t("connection.rememberPasswordSaveFailed", { message: connectionErrorMessage(error) }));
|
||||
}
|
||||
ensureLocalConnectionAttemptActive(connectionId, localAttempt);
|
||||
})();
|
||||
connectInFlight.set(connectionId, connectPromise);
|
||||
try {
|
||||
await connectPromise;
|
||||
ensureLocalConnectionAttemptActive(connectionId, localAttempt);
|
||||
if (options.activate !== false) activeConnectionId.value = connectionId;
|
||||
} catch (e) {
|
||||
if (isCancelledLocalConnectionAttempt(connectionId, localAttempt)) {
|
||||
clearConnectionError(connectionId);
|
||||
throw new Error(CONNECTION_ATTEMPT_CANCELLED_MESSAGE);
|
||||
}
|
||||
if (isCancelledConnectionAttempt(e)) {
|
||||
clearConnectionError(connectionId);
|
||||
if (isCurrentLocalConnectionAttempt(connectionId, localAttempt)) clearConnectionError(connectionId);
|
||||
throw e;
|
||||
}
|
||||
if (isSupersededConnectionAttempt(e) && connectedIds.value.has(connectionId)) {
|
||||
clearConnectionError(connectionId);
|
||||
return;
|
||||
}
|
||||
// 后台搜索触发的重连失败只留一行提示,避免把完整驱动错误(如旧版 SQL Server 的 TLS 提示)
|
||||
@@ -10271,6 +10300,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
handleConnectionLivenessMessage,
|
||||
metadataGenerationFor,
|
||||
disconnectAndForgetConnectionPassword,
|
||||
retirePasswordAfterChange,
|
||||
hasSessionCredential,
|
||||
closeDatabaseConnection,
|
||||
ensureConnected,
|
||||
|
||||
Reference in new issue
Block a user