fix(runtime): bound cloud db query timeout (#1979)
This commit is contained in:
@@ -385,7 +385,12 @@
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"image": { "type": "string", "minLength": 1 },
|
||||
"poolMax": { "type": "integer", "minimum": 1 }
|
||||
"poolMax": { "type": "integer", "minimum": 1 },
|
||||
"connectionTimeoutMs": { "type": "integer", "minimum": 1 },
|
||||
"queryTimeoutMs": { "type": "integer", "minimum": 1 },
|
||||
"queryRetryMaxAttempts": { "type": "integer", "minimum": 1 },
|
||||
"queryRetryInitialDelayMs": { "type": "integer", "minimum": 0 },
|
||||
"queryRetryMaxDelayMs": { "type": "integer", "minimum": 0 }
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
|
||||
@@ -304,6 +304,7 @@ lanes:
|
||||
image: postgres:16-alpine
|
||||
poolMax: 4
|
||||
connectionTimeoutMs: 5000
|
||||
queryTimeoutMs: 3000
|
||||
queryRetryMaxAttempts: 5
|
||||
queryRetryInitialDelayMs: 250
|
||||
queryRetryMaxDelayMs: 5000
|
||||
|
||||
@@ -109,17 +109,22 @@ export function createConfiguredCloudRuntimeStore(options = {}) {
|
||||
return createCloudRuntimeStore(options);
|
||||
}
|
||||
|
||||
export function buildPostgresPoolConfig({ dbUrl, sslMode = "require", timeoutMs, poolMax } = {}) {
|
||||
export function buildPostgresPoolConfig({ dbUrl, sslMode = "require", timeoutMs, poolMax, queryTimeoutMs } = {}) {
|
||||
const normalizedSslMode = normalizePostgresSslMode(sslMode);
|
||||
const normalizedPoolMax = normalizeRuntimePoolMax(poolMax);
|
||||
const normalizedQueryTimeoutMs = queryTimeoutMs === undefined || queryTimeoutMs === null || String(queryTimeoutMs).trim() === ""
|
||||
? null
|
||||
: normalizeRuntimeTimeoutMs(queryTimeoutMs);
|
||||
return {
|
||||
connectionString: normalizePostgresConnectionStringForSslMode(dbUrl, normalizedSslMode),
|
||||
ssl: postgresSslOption(normalizedSslMode),
|
||||
connectionTimeoutMillis: normalizeRuntimeTimeoutMs(timeoutMs),
|
||||
...(normalizedQueryTimeoutMs !== null ? { query_timeout: normalizedQueryTimeoutMs, statement_timeout: normalizedQueryTimeoutMs } : {}),
|
||||
...(normalizedPoolMax !== null ? { max: normalizedPoolMax } : {})
|
||||
};
|
||||
}
|
||||
|
||||
const RUNTIME_DB_QUERY_TIMEOUT_MS_ENV = "HWLAB_CLOUD_DB_QUERY_TIMEOUT_MS";
|
||||
const RUNTIME_DB_QUERY_RETRY_MAX_ATTEMPTS_ENV = "HWLAB_CLOUD_DB_QUERY_RETRY_MAX_ATTEMPTS";
|
||||
const RUNTIME_DB_QUERY_RETRY_INITIAL_DELAY_MS_ENV = "HWLAB_CLOUD_DB_QUERY_RETRY_INITIAL_DELAY_MS";
|
||||
const RUNTIME_DB_QUERY_RETRY_MAX_DELAY_MS_ENV = "HWLAB_CLOUD_DB_QUERY_RETRY_MAX_DELAY_MS";
|
||||
@@ -1952,6 +1957,7 @@ export class PostgresCloudRuntimeStore {
|
||||
dbUrl: this.dbUrl,
|
||||
sslMode: this.sslMode,
|
||||
timeoutMs: this.env?.HWLAB_CLOUD_DB_PROBE_TIMEOUT_MS,
|
||||
queryTimeoutMs: this.env?.[RUNTIME_DB_QUERY_TIMEOUT_MS_ENV],
|
||||
poolMax: this.env?.[RUNTIME_DB_POOL_MAX_ENV]
|
||||
}));
|
||||
if (typeof this.pool.on === "function") {
|
||||
|
||||
@@ -1004,6 +1004,9 @@ function runtimeStoreEnvForProfile(deploy, profile, serviceId) {
|
||||
if (Number.isInteger(postgres.connectionTimeoutMs)) {
|
||||
env.HWLAB_CLOUD_DB_PROBE_TIMEOUT_MS = String(postgres.connectionTimeoutMs);
|
||||
}
|
||||
if (Number.isInteger(postgres.queryTimeoutMs)) {
|
||||
env.HWLAB_CLOUD_DB_QUERY_TIMEOUT_MS = String(postgres.queryTimeoutMs);
|
||||
}
|
||||
if (Number.isInteger(postgres.queryRetryMaxAttempts)) {
|
||||
env.HWLAB_CLOUD_DB_QUERY_RETRY_MAX_ATTEMPTS = String(postgres.queryRetryMaxAttempts);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user