From cbce34afbb5f1cb1320c759e47f53415d2a411cf Mon Sep 17 00:00:00 2001 From: Harry Kao Date: Mon, 17 Oct 2022 12:52:47 -0700 Subject: [PATCH] Invalidate connection after client-side timeout. The `query_timeout` feature of the `pg` package helps handle stuck TCP connections more quickly and gracefully by implementing a client-side timeout: https://github.com/brianc/node-postgres/issues/1713 Sequelize started passing this dialect-specific option through to `pg` here: https://github.com/sequelize/sequelize/pull/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 --- src/dialects/postgres/query.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dialects/postgres/query.js b/src/dialects/postgres/query.js index 4f4f444cb081..1b51b704688c 100644 --- a/src/dialects/postgres/query.js +++ b/src/dialects/postgres/query.js @@ -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; }