diff --git a/lib/dialects/postgres/connection-manager.js b/lib/dialects/postgres/connection-manager.js index 0cf2f793743d..a07669efcdcc 100644 --- a/lib/dialects/postgres/connection-manager.js +++ b/lib/dialects/postgres/connection-manager.js @@ -113,8 +113,10 @@ class ConnectionManager extends AbstractConnectionManager { // This should help with backends incorrectly considering idle clients to be dead and prematurely disconnecting them. // this feature has been added in pg module v6.0.0, check pg/CHANGELOG.md 'keepAlive', - // Times out queries after a set time in milliseconds. Added in pg v7.3 + // Times out queries after a set time in milliseconds in the database end. Added in pg v7.3 'statement_timeout', + // Times out queries after a set time in milliseconds in client end, query would be still running in database end. + 'query_timeout', // Terminate any session with an open transaction that has been idle for longer than the specified duration in milliseconds. Added in pg v7.17.0 only supported in postgres >= 10 'idle_in_transaction_session_timeout' ])); diff --git a/test/integration/dialects/postgres/connection-manager.test.js b/test/integration/dialects/postgres/connection-manager.test.js index 0dbd9641980a..b6924416abb2 100644 --- a/test/integration/dialects/postgres/connection-manager.test.js +++ b/test/integration/dialects/postgres/connection-manager.test.js @@ -39,6 +39,14 @@ if (dialect.match(/^postgres/)) { // `notice` is Postgres's default expect(result[0].client_min_messages).to.equal('notice'); }); + + it('should time out the query request when the query runs beyond the configured query_timeout', async () => { + const sequelize = Support.createSequelizeInstance({ + dialectOptions: { query_timeout: 100 } + }); + const error = await sequelize.query('select pg_sleep(2)').catch(e => e); + expect(error.message).to.equal('Query read timeout'); + }); }); describe('Dynamic OIDs', () => {