Skip to content

Commit 869dd06

Browse files
committed
chore: refactor connection kill
1 parent 4bfc1cc commit 869dd06

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/lib/db.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,12 @@ export const init: (config: PoolConfig) => {
115115
}
116116
return { data: res.rows, error: null }
117117
} catch (error: any) {
118-
if (error.constructor.name === 'DatabaseError') {
118+
if (
119+
error.constructor.name === 'DatabaseError' &&
120+
// If that's a global packet handling error it's raised as a "DatabaseError" but really is a
121+
// underlying parser error, we want to error to be treated as a connection error and end the pool
122+
!(error.message && error.message.startsWith('exception received while handling packet'))
123+
) {
119124
// Roughly based on:
120125
// - https://github.com/postgres/postgres/blob/fc4089f3c65a5f1b413a3299ba02b66a8e5e37d0/src/interfaces/libpq/fe-protocol3.c#L1018
121126
// - https://github.com/brianc/node-postgres/blob/b1a8947738ce0af004cb926f79829bb2abc64aa6/packages/pg/lib/native/query.js#L33

0 commit comments

Comments
 (0)