fix: resolve MySQL connection state desync after disconnect/reconnect
- Use synchronous pool removal in desktop disconnect_db to prevent race condition when user quickly disconnects and reconnects - Rename recordMetadataLoadError to recordConnectionLostError and export it for cross-store reuse - Sync query execution errors back to connection state via recordConnectionLostError in queryStore catch blocks - Add backend check_connection_health method (dbx-core) with Tauri command and web route for proactive pool verification - Add frontend checkConnectionHealth API (tauri.ts/http.ts/api.ts) - Enhance ensureConnected to verify backend pool health before assuming connection is valid, auto-reconnect if stale
This commit is contained in:
1 parent
4346192713
commit
e2f68de455
10 files changed
+92
-24
No files matched your search
@@ -1638,6 +1638,8 @@ export const useQueryStore = defineStore("query", () => {
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.error("[DBX][executeTabSql:error]", { traceId, elapsed: elapsed(), error: e });
|
||||
// Sync connection state if the error indicates a lost connection
|
||||
useConnectionStore().recordConnectionLostError(tab.connectionId, e);
|
||||
const current = tabs.value.find((t) => t.id === id);
|
||||
if (current?.executionId === executionId) {
|
||||
current.result = toErrorResult(e);
|
||||
@@ -1787,6 +1789,8 @@ export const useQueryStore = defineStore("query", () => {
|
||||
}
|
||||
return canceled;
|
||||
} catch (e: any) {
|
||||
// Sync connection state if the error indicates a lost connection
|
||||
if (tab) useConnectionStore().recordConnectionLostError(tab.connectionId, e);
|
||||
const current = tabs.value.find((t) => t.id === id);
|
||||
if (current && current.executionId === executionId) {
|
||||
current.isCancelling = false;
|
||||
@@ -1833,12 +1837,15 @@ export const useQueryStore = defineStore("query", () => {
|
||||
function notifyConnectionMayBeLost() {
|
||||
const stuck = tabs.value.filter((t) => t.isExecuting);
|
||||
if (stuck.length > 0) {
|
||||
const connStore = useConnectionStore();
|
||||
stuck.forEach((tab) => {
|
||||
tab.isExecuting = false;
|
||||
tab.isCancelling = false;
|
||||
tab.queryExecutionStartedAt = undefined;
|
||||
tab.executionId = undefined;
|
||||
tab.result = toErrorResult(new Error(t("editor.connectionMayBeLost")));
|
||||
const error = new Error(t("editor.connectionMayBeLost"));
|
||||
tab.result = toErrorResult(error);
|
||||
connStore.recordConnectionLostError(tab.connectionId, error);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user