Skip to content

Commit

Permalink
Invalidate connection after client-side timeout.
Browse files Browse the repository at this point in the history
The `query_timeout` feature of the `pg` package helps handle stuck TCP
connections more quickly and gracefully by implementing a client-side
timeout:

brianc/node-postgres#1713

Sequelize started passing this dialect-specific option through to `pg` here:

sequelize#13258

I believe we also want to invalidate the connection when a client-side
timeout occurs. We shouldn't try to reuse the stuck connection
because...it's stuck.

This PR updates the error handling code so that the connection is
invalidated if the error matches the one thrown from here:

https://github.com/brianc/node-postgres/blob/5538df6b446f4b4f921947b460fe38acb897e579/packages/pg/lib/client.js#L529
  • Loading branch information
harrykao committed Oct 17, 2022
1 parent fe3f470 commit cbce34a
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/dialects/postgres/query.js
Expand Up @@ -51,6 +51,7 @@ export class PostgresQuery extends AbstractQuery {
|| /Unable to set non-blocking to true/i.test(error)
|| /SSL SYSCALL error: EOF detected/i.test(error)
|| /Local: Authentication failure/i.test(error)
|| error.message === 'Query read timeout'
) {
connection._invalid = true;
}
Expand Down

0 comments on commit cbce34a

Please sign in to comment.