From c3dc02213fb945ffa2407d16fe4e3ac1a9829646 Mon Sep 17 00:00:00 2001 From: Ben Page Date: Fri, 31 Oct 2014 11:53:58 -0500 Subject: [PATCH] fixed leak of idle connections --- README.md | 2 +- lib/connection-pool.js | 6 +++--- lib/pooled-connection.js | 6 +++--- package.json | 8 ++------ 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index e15be4c..074c791 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ It is then available to be reused. ##Class: PooledConnection * An extension of the tedious [Connection](http://pekim.github.com/tedious/api-connection.html) object. -### PooledConnection.release() +### pooledConnection.release() ## Version 0.2.x Breaking Changes * To acquire a connection, call on acquire() on a ConnectionPool rather than requestConnection(). diff --git a/lib/connection-pool.js b/lib/connection-pool.js index 350028c..b5283f9 100644 --- a/lib/connection-pool.js +++ b/lib/connection-pool.js @@ -17,11 +17,11 @@ function ConnectionPool(poolConfig, connectionConfig) { }); }, destroy: function (connection) { - if (!connection.isEnded) //con.close() calls pool.destroy(), which calls con.close() - isEnded stops looping - connection.close(); + connection.destroyed = true; + connection.close(); }, validate: function(connection) { - return !connection.closed && !connection.isEnded; + return !connection.closed; }, max: poolConfig.max || 10, min: poolConfig.min || 0, diff --git a/lib/pooled-connection.js b/lib/pooled-connection.js index a6ff715..2f6e369 100644 --- a/lib/pooled-connection.js +++ b/lib/pooled-connection.js @@ -4,13 +4,13 @@ function PooledConnection(connectionPool, config) { var self = this; this.connectionPool = connectionPool; - this.isEnded = false; + this.destroyed = false; Connection.call(this, config); this.on('end', function () { - self.isEnded = true; - self.connectionPool.pool.destroy(self); + if (!this.destroyed) + self.connectionPool.pool.destroy(self); }); } diff --git a/package.json b/package.json index 38ccef3..fe548cb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tedious-connection-pool", - "version": "0.2.3", + "version": "0.2.4", "description": "Connection Pool for tedious.", "main": "lib/connection-pool.js", "dependencies": { @@ -23,10 +23,6 @@ "email": "mike.pilsbury@gmail.com" }, "contributors": [ - { - "name": "e11137", - "email": "rogelio.canedo@gmail.com" - }, { "name": "Ben Page", "email": "ben.page@openreign.com" @@ -45,7 +41,7 @@ "licenses": [ { "type": "MIT", - "url": "https://github.com/brentertz/scapegoat/blob/master/LICENSE-MIT" + "url": "http://opensource.org/licenses/MIT" } ], "devDependencies": {