fix(postgres): correct query and connection timeout handling under SSH tunnel

This commit is contained in:
Anubis authored and GitHub committed 2026-08-07 13:45:00 +08:00
1 parent b8144da5f0
commit 143fd96c3f
6 files changed
+287 -52

No files matched your search

@@ -34,7 +34,7 @@ describe("connectionAttemptTimeout", () => {
expect(connectionAttemptTimeoutMs({ db_type: "access", connect_timeout_secs: 45, transport_layers: [] })).toBe(47_000);
});
it("includes HTTP tunnel connection timeout values", () => {
it("adds HTTP tunnel setup and tunneled endpoint probe budgets", () => {
expect(
connectionAttemptTimeoutMs({
db_type: "mysql",
@@ -48,6 +48,25 @@ describe("connectionAttemptTimeout", () => {
},
],
}),
).toBe(37_000);
});
it("adds SSH setup and tunneled endpoint probe budgets", () => {
expect(
connectionAttemptTimeoutMs({
db_type: "postgres",
connect_timeout_secs: 10,
transport_layers: [
{
type: "ssh",
id: "ssh",
host: "bastion.example.com",
port: 22,
user: "dbx",
connect_timeout_secs: 5,
},
],
}),
).toBe(27_000);
});
@@ -81,7 +100,7 @@ describe("connectionAttemptTimeout", () => {
},
(profileId) => (profileId === profile.id ? profile : undefined),
),
).toBe(42_000);
).toBe(52_000);
});
it("keeps disabled shared layers outside the attempt deadline", () => {
+21
View File
@@ -0,0 +1,21 @@
import { describe, expect, it } from "vitest";
import { frontendQueryTimeoutSecsForSql, queryTimeoutSecsForConnection } from "@/lib/sql/queryTimeout";
describe("queryTimeout", () => {
it("lets PostgreSQL row queries use the backend inactivity timeout", () => {
expect(frontendQueryTimeoutSecsForSql("SELECT * FROM sample_records LIMIT 2000", "postgres", 30)).toBe(0);
expect(frontendQueryTimeoutSecsForSql("/* page */\nWITH rows AS (SELECT 1) SELECT * FROM rows", "postgres", 30)).toBe(0);
expect(frontendQueryTimeoutSecsForSql("UPDATE sample_records SET state = 'ready' RETURNING id", "postgres", 30)).toBe(0);
});
it("keeps the frontend guard for non-row PostgreSQL statements", () => {
expect(frontendQueryTimeoutSecsForSql("UPDATE sample_records SET state = 'ready'", "postgres", 30)).toBe(60);
expect(frontendQueryTimeoutSecsForSql("INSERT INTO sample_records(note) VALUES ('RETURNING is text')", "postgres", 30)).toBe(60);
expect(frontendQueryTimeoutSecsForSql("UPDATE sample_records SET note = 'ready' /* RETURNING */", "postgres", 30)).toBe(60);
});
it("keeps the existing frontend guard for other database types", () => {
expect(frontendQueryTimeoutSecsForSql("SELECT * FROM sample_records LIMIT 2000", "mysql", 30)).toBe(60);
expect(queryTimeoutSecsForConnection({ query_timeout_secs: undefined })).toBe(60);
});
});