Skip to content

Commit 5744206

Browse files
committed
feat(query): add idle_session_timeout for idle session auto-close
1 parent 2d4d29e commit 5744206

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/lib/db.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,10 @@ export const init: (config: PoolConfig) => {
118118
attributes: { sql: trackQueryInSentry ? sql : 'custom' },
119119
},
120120
async () => {
121+
// Use statement_timeout AND idle_session_timeout to ensure the connection will be killed even if idle after
122+
// timeout time.
121123
const statementTimeoutQueryPrefix = statementQueryTimeout
122-
? `SET statement_timeout='${statementQueryTimeout}s';`
124+
? `SET statement_timeout='${statementQueryTimeout}s'; SET idle_session_timeout='${statementQueryTimeout}s';`
123125
: ''
124126
// node-postgres need a statement_timeout to kill the connection when timeout is reached
125127
// otherwise the query will keep running on the database even if query timeout was reached

0 commit comments

Comments
 (0)