mirror of
https://github.com/knex/knex.git
synced 2025-12-28 23:48:58 +00:00
remove disconnected connection from the pool
log disconnects test test test test clean up
This commit is contained in:
parent
ee8660fd0a
commit
02f5ac3726
@ -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);
|
||||
|
||||
@ -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);
|
||||
},
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user