From 099ed62609e5fa0ffe957db076a5fc55f080a682 Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Mon, 22 Jun 2026 22:23:28 +0800 Subject: [PATCH] fix: preserve known connection loss errors --- apps/desktop/src/lib/connectionHealth.ts | 11 +++++++ .../connectionStoreErrorState.test.ts | 33 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/apps/desktop/src/lib/connectionHealth.ts b/apps/desktop/src/lib/connectionHealth.ts index d43f70a19..57527c7c7 100644 --- a/apps/desktop/src/lib/connectionHealth.ts +++ b/apps/desktop/src/lib/connectionHealth.ts @@ -7,11 +7,22 @@ const CONNECTION_ERROR_PATTERNS = [ "connection not found", "connection config not found", "not connected", + "closed the connection", "broken pipe", "reset by peer", "socket closed", "unexpected eof", + "end-of-file", "end-of-file on communication channel", + "server closed session", + "communicating with the server", + "exceeded maximum idle time", + "agent stdin not available", + "agent stdout not available", + "failed to write to agent stdin", + "failed to flush agent stdin", + "关闭的连接", + "连接已关闭", "i/o error", ]; diff --git a/packages/app-tests/connectionStoreErrorState.test.ts b/packages/app-tests/connectionStoreErrorState.test.ts index 5479298ad..09ad8e5b2 100644 --- a/packages/app-tests/connectionStoreErrorState.test.ts +++ b/packages/app-tests/connectionStoreErrorState.test.ts @@ -102,6 +102,39 @@ test("query errors mentioning connection do not mark the connection disconnected } }); +test("known backend connection errors mark the connection disconnected", async () => { + const restoreStorage = installMemoryStorage(); + const messages = [ + "java.sql.SQLRecoverableException: 关闭的连接", + "java.sql.SQLRecoverableException: 连接已关闭", + "server closed session with no notification", + "server closed the connection unexpectedly", + "Error occurred while creating a new object: error communicating with the server", + "ORA-02396: exceeded maximum idle time, please connect again", + "Agent stdin not available", + "Failed to write to agent stdin", + ]; + + try { + for (const [index, message] of messages.entries()) { + setActivePinia(createPinia()); + const store = useConnectionStore(); + const connectionId = `conn-${index}`; + store.addEphemeralConnection(conn(connectionId)); + store.activeConnectionId = connectionId; + + const marked = store.recordConnectionLostError(connectionId, new Error(message)); + + assert.equal(marked, true, message); + assert.equal(store.connectedIds.has(connectionId), false, message); + assert.equal(store.activeConnectionId, null, message); + } + await new Promise((resolve) => setTimeout(resolve, 0)); + } finally { + restoreStorage(); + } +}); + test("explicit lost-connection marker clears state without relying on error text", async () => { const restoreStorage = installMemoryStorage(); try {