Skip to content

fix: add a maximum query time limit #928

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/server/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const PG_META_DB_PASSWORD = (await getSecret('PG_META_DB_PASSWORD')) || 'postgre
const PG_META_DB_SSL_MODE = process.env.PG_META_DB_SSL_MODE || 'disable'

const PG_CONN_TIMEOUT_SECS = Number(process.env.PG_CONN_TIMEOUT_SECS || 15)
const PG_QUERY_TIMEOUT_SECS = Number(process.env.PG_QUERY_TIMEOUT_SECS || 55)

export let PG_CONNECTION = process.env.PG_META_DB_URL
if (!PG_CONNECTION) {
Expand Down Expand Up @@ -58,6 +59,7 @@ export const PG_META_MAX_RESULT_SIZE = process.env.PG_META_MAX_RESULT_SIZE_MB
export const DEFAULT_POOL_CONFIG: PoolConfig = {
max: 1,
connectionTimeoutMillis: PG_CONN_TIMEOUT_SECS * 1000,
query_timeout: PG_QUERY_TIMEOUT_SECS * 1000,
ssl: PG_META_DB_SSL_ROOT_CERT ? { ca: PG_META_DB_SSL_ROOT_CERT } : undefined,
application_name: `postgres-meta ${pkg.version}`,
maxResultSize: PG_META_MAX_RESULT_SIZE,
Expand Down
2 changes: 2 additions & 0 deletions src/server/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export function translateErrorToResponseCode(
return 504
} else if (error.message === 'sorry, too many clients already') {
return 503
} else if (error.message === 'Query read timeout') {
return 408
}
return defaultResponseCode
}