File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -24,13 +24,20 @@ import {
2424const logger = createLogger ( 'SocketDatabase' )
2525
2626const connectionString = env . DATABASE_URL
27+ /**
28+ * Server-side safety net for runaway queries and abandoned transactions.
29+ * See `packages/db/index.ts` for rationale.
30+ */
2731const socketDb = drizzle (
2832 postgres ( connectionString , {
2933 prepare : false ,
3034 idle_timeout : 10 ,
3135 connect_timeout : 20 ,
3236 max : 10 ,
3337 onnotice : ( ) => { } ,
38+ connection : {
39+ options : '-c statement_timeout=90000 -c idle_in_transaction_session_timeout=90000' ,
40+ } ,
3441 } ) ,
3542 { schema }
3643)
Original file line number Diff line number Diff line change @@ -10,12 +10,27 @@ if (!connectionString) {
1010 throw new Error ( 'Missing DATABASE_URL environment variable' )
1111}
1212
13+ /**
14+ * Server-side safety net for runaway queries and abandoned transactions:
15+ * - `statement_timeout=90000` kills any single statement still running
16+ * after 90s. Protects against pathological queries.
17+ * - `idle_in_transaction_session_timeout=90000` kills a session that has
18+ * opened a transaction and gone idle for 90s. Protects against
19+ * transactions that hold row locks while waiting on external I/O.
20+ *
21+ * These are last-resort caps — application code should never approach
22+ * them. Migrations or admin scripts that legitimately need longer limits
23+ * must construct their own client with overrides.
24+ */
1325const postgresClient = postgres ( connectionString , {
1426 prepare : false ,
1527 idle_timeout : 20 ,
1628 connect_timeout : 30 ,
1729 max : 10 ,
1830 onnotice : ( ) => { } ,
31+ connection : {
32+ options : '-c statement_timeout=90000 -c idle_in_transaction_session_timeout=90000' ,
33+ } ,
1934} )
2035
2136export const db = drizzle ( postgresClient , { schema } )
You can’t perform that action at this time.
0 commit comments