diff --git a/clients/pool.js b/clients/pool.js index 4a4c85342..54c18c61e 100644 --- a/clients/pool.js +++ b/clients/pool.js @@ -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); diff --git a/clients/server/mysql.js b/clients/server/mysql.js index d657e193c..191e43553 100644 --- a/clients/server/mysql.js +++ b/clients/server/mysql.js @@ -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); },