Skip to content

Commit 71585b4

Browse files
authored
Merge pull request #928 from supabase/fix/add-query-timeout
fix: add a maximum query time limit
2 parents 1bbd3f1 + 4f3b6d7 commit 71585b4

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

Diff for: src/server/constants.ts

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const PG_META_DB_PASSWORD = (await getSecret('PG_META_DB_PASSWORD')) || 'postgre
1616
const PG_META_DB_SSL_MODE = process.env.PG_META_DB_SSL_MODE || 'disable'
1717

1818
const PG_CONN_TIMEOUT_SECS = Number(process.env.PG_CONN_TIMEOUT_SECS || 15)
19+
const PG_QUERY_TIMEOUT_SECS = Number(process.env.PG_QUERY_TIMEOUT_SECS || 55)
1920

2021
export let PG_CONNECTION = process.env.PG_META_DB_URL
2122
if (!PG_CONNECTION) {
@@ -58,6 +59,7 @@ export const PG_META_MAX_RESULT_SIZE = process.env.PG_META_MAX_RESULT_SIZE_MB
5859
export const DEFAULT_POOL_CONFIG: PoolConfig = {
5960
max: 1,
6061
connectionTimeoutMillis: PG_CONN_TIMEOUT_SECS * 1000,
62+
query_timeout: PG_QUERY_TIMEOUT_SECS * 1000,
6163
ssl: PG_META_DB_SSL_ROOT_CERT ? { ca: PG_META_DB_SSL_ROOT_CERT } : undefined,
6264
application_name: `postgres-meta ${pkg.version}`,
6365
maxResultSize: PG_META_MAX_RESULT_SIZE,

Diff for: src/server/utils.ts

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export function translateErrorToResponseCode(
2929
return 504
3030
} else if (error.message === 'sorry, too many clients already') {
3131
return 503
32+
} else if (error.message === 'Query read timeout') {
33+
return 408
3234
}
3335
return defaultResponseCode
3436
}

0 commit comments

Comments
 (0)