Skip to content

Commit 3ca085d

Browse files
sincerekamalkamal-brillsdepold
authored
feat(postgres): support query_timeout dialect option (#13258)
* Add query_timeout option to postgres dialectOptions * fix: lint issues in the test file Co-authored-by: Kamalakannan Jayaraman <kamalakannan.j@brillio.com> Co-authored-by: Sascha Depold <sdepold@users.noreply.github.com>
1 parent e86c884 commit 3ca085d

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

lib/dialects/postgres/connection-manager.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,10 @@ class ConnectionManager extends AbstractConnectionManager {
113113
// This should help with backends incorrectly considering idle clients to be dead and prematurely disconnecting them.
114114
// this feature has been added in pg module v6.0.0, check pg/CHANGELOG.md
115115
'keepAlive',
116-
// Times out queries after a set time in milliseconds. Added in pg v7.3
116+
// Times out queries after a set time in milliseconds in the database end. Added in pg v7.3
117117
'statement_timeout',
118+
// Times out queries after a set time in milliseconds in client end, query would be still running in database end.
119+
'query_timeout',
118120
// 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
119121
'idle_in_transaction_session_timeout'
120122
]));

test/integration/dialects/postgres/connection-manager.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ if (dialect.match(/^postgres/)) {
3939
// `notice` is Postgres's default
4040
expect(result[0].client_min_messages).to.equal('notice');
4141
});
42+
43+
it('should time out the query request when the query runs beyond the configured query_timeout', async () => {
44+
const sequelize = Support.createSequelizeInstance({
45+
dialectOptions: { query_timeout: 100 }
46+
});
47+
const error = await sequelize.query('select pg_sleep(2)').catch(e => e);
48+
expect(error.message).to.equal('Query read timeout');
49+
});
4250
});
4351

4452
describe('Dynamic OIDs', () => {

0 commit comments

Comments
 (0)