From 651955575fc7f136b21b0ab47bbe83b80a96735c Mon Sep 17 00:00:00 2001 From: dkarpman Date: Tue, 22 Apr 2014 15:41:46 -0700 Subject: [PATCH 1/6] Update pool.js --- lib/pool.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/pool.js b/lib/pool.js index 67140e6b9..9cd09d15a 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -70,7 +70,8 @@ var pools = { if(err) { pool.destroy(client); } else { - pool.release(client); + pool.destroy(client); + // pool.release(client); } }); }); From 78cc738d280c35e9b7f1f8f459d526a0fd122c1a Mon Sep 17 00:00:00 2001 From: dkarpman Date: Tue, 22 Apr 2014 16:07:09 -0700 Subject: [PATCH 2/6] Update index.js --- lib/index.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index b78e4caa9..d92f53386 100644 --- a/lib/index.js +++ b/lib/index.js @@ -41,12 +41,22 @@ PG.prototype.connect = function(config, callback) { callback = config; config = null; } - var pool = this.pools.getOrCreate(config); + var client = new this.Client(config); + client.connect(function(err) { + if(err) { + return callback && callback(err); + } + return callback && callback(null, client, function() { + client.end(); + }); + // client.query() + }); + /* var pool = this.pools.getOrCreate(config); pool.connect(callback); if(!pool.listeners('error').length) { //propagate errors up to pg object pool.on('error', this.emit.bind(this, 'error')); - } + } */ }; // cancel the query runned by the given client From 57018b9bfc3ee501ebad29ec0b654e0bc6eac172 Mon Sep 17 00:00:00 2001 From: dkarpman Date: Tue, 14 Oct 2014 17:47:08 -0700 Subject: [PATCH 3/6] Update index.js --- lib/index.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/index.js b/lib/index.js index d92f53386..f8e3e2b87 100644 --- a/lib/index.js +++ b/lib/index.js @@ -13,6 +13,8 @@ var PG = function(clientConstructor) { this.pools = pool; this.Connection = Connection; this.types = require('pg-types'); + this.num_connections = 0; + this.max_connections = this.defaults.max_connections; }; util.inherits(PG, EventEmitter); @@ -35,28 +37,26 @@ PG.prototype.end = function() { }); }; - PG.prototype.connect = function(config, callback) { if(typeof config == "function") { callback = config; config = null; } + if(this.max_connections && this.num_connections >= this.max_connections) { + return callback && callback(Error("Connection limit", this.max_connections, "reached")); + } var client = new this.Client(config); + // Max connections waiting to connect + this.num_connections++; client.connect(function(err) { + this.num_connections--; if(err) { return callback && callback(err); } return callback && callback(null, client, function() { client.end(); }); - // client.query() }); - /* var pool = this.pools.getOrCreate(config); - pool.connect(callback); - if(!pool.listeners('error').length) { - //propagate errors up to pg object - pool.on('error', this.emit.bind(this, 'error')); - } */ }; // cancel the query runned by the given client From a6485990231e00794ac15ce972e8f1a7c6aed1b6 Mon Sep 17 00:00:00 2001 From: dkarpman Date: Tue, 14 Oct 2014 17:47:30 -0700 Subject: [PATCH 4/6] Update defaults.js --- lib/defaults.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/defaults.js b/lib/defaults.js index 9f5687b05..21590fa78 100644 --- a/lib/defaults.js +++ b/lib/defaults.js @@ -39,6 +39,7 @@ var defaults = module.exports = { client_encoding: "", ssl: false, + max_connections: 1000, application_name : undefined, fallback_application_name: undefined From 743bc4c21dc703d518ed852eda27b8b4421f780a Mon Sep 17 00:00:00 2001 From: dkarpman Date: Tue, 14 Oct 2014 17:50:18 -0700 Subject: [PATCH 5/6] Update index.js --- lib/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index f8e3e2b87..b46027212 100644 --- a/lib/index.js +++ b/lib/index.js @@ -48,8 +48,9 @@ PG.prototype.connect = function(config, callback) { var client = new this.Client(config); // Max connections waiting to connect this.num_connections++; + var _this = this; client.connect(function(err) { - this.num_connections--; + _this.num_connections--; if(err) { return callback && callback(err); } From 5f20218fbcd9a6b07de9c77f4afe5a712576f4df Mon Sep 17 00:00:00 2001 From: dkarpman Date: Sun, 19 Oct 2014 12:58:11 -0700 Subject: [PATCH 6/6] Update defaults.js --- lib/defaults.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/defaults.js b/lib/defaults.js index 21590fa78..59214865b 100644 --- a/lib/defaults.js +++ b/lib/defaults.js @@ -39,7 +39,7 @@ var defaults = module.exports = { client_encoding: "", ssl: false, - max_connections: 1000, + max_connections: 10000, application_name : undefined, fallback_application_name: undefined