Skip to content

Commit c16c7f6

Browse files
committed
configurable idle timeout on pooled clients
1 parent aa63f50 commit c16c7f6

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

lib/defaults.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ module.exports = {
1212
rows: 0,
1313
//number of connections to use in connection pool
1414
//0 will disable connection pooling
15-
poolSize: 10
15+
poolSize: 10,
16+
//duration of node-pool timeout
17+
poolIdleTimeout: 30000
1618
}

lib/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ var makeConnectFunction = function(ClientConstructor) {
4242
destroy: function(client) {
4343
client.end();
4444
},
45-
max: defaults.poolSize
45+
max: defaults.poolSize,
46+
idleTimeoutMillis: defaults.poolIdleTimeout
4647
});
4748
return pool.acquire(cb);
4849
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var helper = require(__dirname + '/test-helper');
2+
3+
helper.pg.defaults.poolIdleTimeout = 200;
4+
5+
test('idle timeout', function() {
6+
helper.pg.connect(helper.connectionString(), assert.calls(function(err, client) {
7+
assert.isNull(err);
8+
client.query('SELECT NOW()');
9+
//just let this one time out
10+
//test will hang if pool doesn't timeout
11+
}));
12+
});

test/integration/connection-pool/unique-name-tests.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ helper.pg.defaults.password = helper.args.password;
66
helper.pg.defaults.database = helper.args.database;
77
helper.pg.defaults.port = helper.args.port;
88
helper.pg.defaults.host = helper.args.host;
9-
9+
helper.pg.defaults.poolIdleTimeout = 100;
1010
var args = {
1111
user: helper.args.user,
1212
password: helper.args.password,

0 commit comments

Comments
 (0)