fix: show timeout action for SQL execution timeouts
* fix: show timeout action for SQL execution timeouts * fix: detect agent RPC timeout in query error action --------- Co-authored-by: zipg <4047349+zipg@users.noreply.github.com> Co-authored-by: t8y2 <1156263951@qq.com>
This commit is contained in:
3 files changed
+56
-5
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { isQueryTimeoutErrorMessage } from "@/lib/sql/queryError";
|
||||
|
||||
describe("isQueryTimeoutErrorMessage", () => {
|
||||
it("detects DBX query timeout messages", () => {
|
||||
expect(isQueryTimeoutErrorMessage("Query timed out after 30 seconds")).toBe(true);
|
||||
expect(isQueryTimeoutErrorMessage("查询超时 (60s),请检查数据库连接是否正常")).toBe(true);
|
||||
expect(isQueryTimeoutErrorMessage("查詢逾時 (60s),請檢查資料庫連線是否正常")).toBe(true);
|
||||
});
|
||||
|
||||
it("detects statement timeout messages", () => {
|
||||
expect(isQueryTimeoutErrorMessage("ERROR: canceling statement due to statement timeout")).toBe(true);
|
||||
expect(isQueryTimeoutErrorMessage("ERROR: cancelling statement due to statement timeout")).toBe(true);
|
||||
expect(isQueryTimeoutErrorMessage("Statement timed out after 10 seconds")).toBe(true);
|
||||
});
|
||||
|
||||
it("detects generic query execution timeout messages", () => {
|
||||
expect(isQueryTimeoutErrorMessage("SQL execution timed out after 30s")).toBe(true);
|
||||
expect(isQueryTimeoutErrorMessage("Execution Timeout Expired. The timeout period elapsed prior to completion of the operation.")).toBe(true);
|
||||
expect(isQueryTimeoutErrorMessage("Query exceeded maximum execution time")).toBe(true);
|
||||
});
|
||||
|
||||
it("detects agent RPC client-side timeout", () => {
|
||||
expect(isQueryTimeoutErrorMessage("Agent RPC call timed out (30s)")).toBe(true);
|
||||
expect(isQueryTimeoutErrorMessage("Agent RPC call timed out (120s)")).toBe(true);
|
||||
});
|
||||
|
||||
it("does not classify unrelated errors as query timeouts", () => {
|
||||
expect(isQueryTimeoutErrorMessage('syntax error at or near "select"')).toBe(false);
|
||||
expect(isQueryTimeoutErrorMessage("Connection timed out while loading databases")).toBe(false);
|
||||
expect(isQueryTimeoutErrorMessage("PostgreSQL connection pool checkout timed out (5s)")).toBe(false);
|
||||
expect(isQueryTimeoutErrorMessage("Cancel request timed out after 10s.")).toBe(false);
|
||||
expect(isQueryTimeoutErrorMessage("HTTP tunnel script read timed out")).toBe(false);
|
||||
expect(isQueryTimeoutErrorMessage('invalid value for parameter "statement_timeout"')).toBe(false);
|
||||
// Agent RPC errors that are not timeouts must not trigger the action.
|
||||
expect(isQueryTimeoutErrorMessage('Agent RPC error (-1): syntax error at or near "select"')).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
export function isQueryTimeoutErrorMessage(message: string): boolean {
|
||||
const lower = message.toLowerCase();
|
||||
if (lower.includes("query timed out") || lower.includes("查询超时") || lower.includes("查詢逾時")) return true;
|
||||
// Agent RPC client-side timeout (tokio::time::timeout in agent_driver.rs). This is the
|
||||
// fallback when JDBC setQueryTimeout never fires (unsupported/unresponsive driver), so the
|
||||
// backend already treats it as a query timeout (is_agent_rpc_timeout_error in query.rs) —
|
||||
// surface the same action here to stay consistent with the backend.
|
||||
if (lower.startsWith("agent rpc call timed out")) return true;
|
||||
if (/\b(?:canceling|cancelling|canceled|cancelled)\b[\s\S]{0,80}\bstatement\b[\s\S]{0,80}\btimeout\b/.test(lower)) return true;
|
||||
if (/\b(?:connection|connect|pool|checkout|metadata|loading|health check|cancel request|ssh|tunnel)\b/.test(lower)) return false;
|
||||
return (
|
||||
/\b(?:query|statement|sql|execution|execute|executing)\b[\s\S]{0,80}\b(?:timed out|timeout expired|timeout exceeded|time-out)\b/.test(lower) ||
|
||||
/\b(?:timed out|timeout expired|timeout exceeded|time-out)\b[\s\S]{0,80}\b(?:query|statement|sql|execution|execute|executing)\b/.test(lower) ||
|
||||
/\bquery\b[\s\S]{0,80}\bexceeded\b[\s\S]{0,80}\b(?:execution\s+)?time\b/.test(lower)
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user