Skip to content

Commit 4cd56cc

Browse files
Raul Ochoabrianc
Raul Ochoa
authored andcommitted
Make pool name consistent on missing config params (brianc#1279)
* Going red: using a config object creates two pools when missing some params It should only create a pool in a consistent way, even if some params are not provided in the first place. * Delay the pool name generation to make it consistent between calls * Don't fallback to empty object as config is already defined
1 parent e5f0e5d commit 4cd56cc

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ PG.prototype.connect = function(config, callback) {
5454
callback = config;
5555
config = null;
5656
}
57-
var poolName = JSON.stringify(config || {});
5857
if (typeof config == 'string') {
5958
config = new ConnectionParameters(config);
6059
}
@@ -66,6 +65,7 @@ PG.prototype.connect = function(config, callback) {
6665
config.idleTimeoutMillis = config.idleTimeoutMillis || config.poolIdleTimeout || defaults.poolIdleTimeout;
6766
config.log = config.log || config.poolLog || defaults.poolLog;
6867

68+
var poolName = JSON.stringify(config);
6969
this._pools[poolName] = this._pools[poolName] || new this.Pool(config);
7070
var pool = this._pools[poolName];
7171
if(!pool.listeners('error').length) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var helper = require(__dirname + "/../test-helper");
2+
var pg = require(__dirname + "/../../../lib");
3+
4+
pg.connect(helper.config, assert.success(function(client, done) {
5+
assert.equal(Object.keys(pg._pools).length, 1);
6+
pg.connect(helper.config, assert.success(function(client2, done2) {
7+
assert.equal(Object.keys(pg._pools).length, 1);
8+
9+
done();
10+
done2();
11+
pg.end();
12+
}));
13+
}));

0 commit comments

Comments
 (0)