Skip to content

Commit 3d7ef3b

Browse files
committed
fix(webapp): harden runs-list pool timeout and cap validation
Client request timeout now sits above the server max_execution_time (default 40s vs 35s, and the factory forces it to at least exec + 5s), so the server-side cap is what stops a slow query and the client stays connected to receive the error, instead of aborting first and leaving the query running. The numeric caps reject zero and negative values, since ClickHouse treats 0 as unlimited for max_execution_time and max_memory_usage, which would silently disable them.
1 parent 1592856 commit 3d7ef3b

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

apps/webapp/app/env.server.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,10 +2233,14 @@ const EnvironmentSchema = z
22332233
.enum(["log", "error", "warn", "info", "debug"])
22342234
.default("info"),
22352235
RUNS_LIST_CLICKHOUSE_COMPRESSION_REQUEST: z.string().default("1"),
2236-
RUNS_LIST_CLICKHOUSE_REQUEST_TIMEOUT_MS: z.coerce.number().int().default(30_000),
2237-
RUNS_LIST_CLICKHOUSE_MAX_EXECUTION_TIME: z.coerce.number().int().default(35),
2238-
RUNS_LIST_CLICKHOUSE_MAX_THREADS: z.coerce.number().int().default(4),
2239-
RUNS_LIST_CLICKHOUSE_MAX_MEMORY_USAGE: z.coerce.number().int().default(1_073_741_824),
2236+
RUNS_LIST_CLICKHOUSE_REQUEST_TIMEOUT_MS: z.coerce.number().int().positive().default(40_000),
2237+
RUNS_LIST_CLICKHOUSE_MAX_EXECUTION_TIME: z.coerce.number().int().positive().default(35),
2238+
RUNS_LIST_CLICKHOUSE_MAX_THREADS: z.coerce.number().int().positive().default(4),
2239+
RUNS_LIST_CLICKHOUSE_MAX_MEMORY_USAGE: z.coerce
2240+
.number()
2241+
.int()
2242+
.positive()
2243+
.default(1_073_741_824),
22402244
RUNS_LIST_CLICKHOUSE_READONLY: z.enum(["0", "1", "2"]).default("2"),
22412245
/**
22422246
* Dedicated ClickHouse service for queue metrics: the ingestion consumer's inserts and every

apps/webapp/app/services/clickhouse/clickhouseFactory.server.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,19 @@ function initializeRealtimeClickhouseClient(): ClickHouse {
303303
* client-level `max_execution_time` would also kill slow inserts. `readonly=2` enforces read-only
304304
* while still allowing these settings to apply (`readonly=1` rejects them).
305305
*/
306+
/**
307+
* Client request timeout for the runs-list pool, forced above the server-side `max_execution_time`
308+
* so the server cap is what stops a slow query and the client stays connected to receive that
309+
* error. If the client timed out first, it would abort while ClickHouse kept executing, which is
310+
* the abandoned-query behaviour this pool is trying to prevent.
311+
*/
312+
function getRunsListRequestTimeoutMs() {
313+
return Math.max(
314+
env.RUNS_LIST_CLICKHOUSE_REQUEST_TIMEOUT_MS,
315+
(env.RUNS_LIST_CLICKHOUSE_MAX_EXECUTION_TIME + 5) * 1000
316+
);
317+
}
318+
306319
function getRunsListClickhouseSettings(): ClickHouseSettings {
307320
const settings: ClickHouseSettings = {
308321
max_execution_time: env.RUNS_LIST_CLICKHOUSE_MAX_EXECUTION_TIME,
@@ -345,7 +358,7 @@ function initializeRunsListClickhouseClient(): ClickHouse {
345358
request: env.RUNS_LIST_CLICKHOUSE_COMPRESSION_REQUEST === "1",
346359
},
347360
maxOpenConnections: env.RUNS_LIST_CLICKHOUSE_MAX_OPEN_CONNECTIONS,
348-
requestTimeoutMs: env.RUNS_LIST_CLICKHOUSE_REQUEST_TIMEOUT_MS,
361+
requestTimeoutMs: getRunsListRequestTimeoutMs(),
349362
clickhouseSettings: getRunsListClickhouseSettings(),
350363
});
351364
}
@@ -591,7 +604,7 @@ function buildOrgClickhouseClient(url: string, clientType: ClientType): ClickHou
591604
request: env.RUNS_LIST_CLICKHOUSE_COMPRESSION_REQUEST === "1",
592605
},
593606
maxOpenConnections: env.RUNS_LIST_CLICKHOUSE_MAX_OPEN_CONNECTIONS,
594-
requestTimeoutMs: env.RUNS_LIST_CLICKHOUSE_REQUEST_TIMEOUT_MS,
607+
requestTimeoutMs: getRunsListRequestTimeoutMs(),
595608
clickhouseSettings: getRunsListClickhouseSettings(),
596609
});
597610
case "standard":

0 commit comments

Comments
 (0)