remove disconnected connection from the pool

log disconnects

test

test

test

test

clean up
This commit is contained in:
Will Schmid 2014-03-17 14:31:06 -04:00
parent ee8660fd0a
commit 02f5ac3726
2 changed files with 7 additions and 7 deletions

View File

@ -33,6 +33,13 @@ Pool.prototype = {
create: function(callback) {
var promise = pool.client.getRawConnection()
.tap(function(connection) {
// remove connection from the pool if the connection disconnects
connection.on('error', function (err) {
//console.log('connection error: ' + err);
pool.poolInstance.destroy(connection);
});
connection.__cid = _.uniqueId('__cid');
if (pool.config.afterCreate) {
return Promise.promisify(pool.config.afterCreate)(connection);

View File

@ -45,13 +45,6 @@ exports.Client = ServerBase.extend({
// connection needs to be added to the pool.
getRawConnection: function() {
var connection = mysql.createConnection(this.connectionSettings);
// handle connection termination so the process does not crash
connection.on('close', function (err) {
//console.log('MySQL connection closed.');
});
connection.on('error', function (err) {
//console.log('MySQL connection error: ' + err);
});
return Promise.promisify(connection.connect, connection)().yield(connection);
},