Skip to content

Commit

Permalink
fixed leak of idle connections
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-page committed Oct 31, 2014
1 parent ca9014c commit c3dc022
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down
6 changes: 3 additions & 3 deletions lib/connection-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions lib/pooled-connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down
8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -23,10 +23,6 @@
"email": "[email protected]"
},
"contributors": [
{
"name": "e11137",
"email": "[email protected]"
},
{
"name": "Ben Page",
"email": "[email protected]"
Expand All @@ -45,7 +41,7 @@
"licenses": [
{
"type": "MIT",
"url": "https://github.com/brentertz/scapegoat/blob/master/LICENSE-MIT"
"url": "http://opensource.org/licenses/MIT"
}
],
"devDependencies": {
Expand Down

0 comments on commit c3dc022

Please sign in to comment.