diff --git a/lib/defaults.js b/lib/defaults.js index 52b30896..e60c7437 100644 --- a/lib/defaults.js +++ b/lib/defaults.js @@ -12,5 +12,7 @@ module.exports = { rows: 0, //number of connections to use in connection pool //0 will disable connection pooling - poolSize: 10 + poolSize: 10, + //duration of node-pool timeout + poolIdleTimeout: 30000 } diff --git a/lib/index.js b/lib/index.js index 2991b58d..f134aca2 100644 --- a/lib/index.js +++ b/lib/index.js @@ -42,7 +42,8 @@ var makeConnectFunction = function(ClientConstructor) { destroy: function(client) { client.end(); }, - max: defaults.poolSize + max: defaults.poolSize, + idleTimeoutMillis: defaults.poolIdleTimeout }); return pool.acquire(cb); } diff --git a/test/integration/connection-pool/idle-timeout-tests.js b/test/integration/connection-pool/idle-timeout-tests.js new file mode 100644 index 00000000..342442e2 --- /dev/null +++ b/test/integration/connection-pool/idle-timeout-tests.js @@ -0,0 +1,12 @@ +var helper = require(__dirname + '/test-helper'); + +helper.pg.defaults.poolIdleTimeout = 200; + +test('idle timeout', function() { + helper.pg.connect(helper.connectionString(), assert.calls(function(err, client) { + assert.isNull(err); + client.query('SELECT NOW()'); + //just let this one time out + //test will hang if pool doesn't timeout + })); +}); diff --git a/test/integration/connection-pool/unique-name-tests.js b/test/integration/connection-pool/unique-name-tests.js index a95bce49..84dda439 100644 --- a/test/integration/connection-pool/unique-name-tests.js +++ b/test/integration/connection-pool/unique-name-tests.js @@ -6,7 +6,7 @@ helper.pg.defaults.password = helper.args.password; helper.pg.defaults.database = helper.args.database; helper.pg.defaults.port = helper.args.port; helper.pg.defaults.host = helper.args.host; - +helper.pg.defaults.poolIdleTimeout = 100; var args = { user: helper.args.user, password: helper.args.password,