Commit d1ff8e9d authored by Girish Ramakrishnan's avatar Girish Ramakrishnan

Fix crash when mysql crashes

parent 70743bd2
......@@ -56,6 +56,10 @@ function initialize(callback) {
});
gConnectionPool.on('connection', function (connection) {
// connection objects are re-used. so we have to attach to the event here (once) to prevent crash
// note the pool also has an 'acquire' event but that is called whenever we do a getConnection()
connection.on('error', (error) => debug(`Connection ${connection.threadId} error: ${error.message}`));
connection.query('USE ' + gDatabase.name);
connection.query('SET SESSION sql_mode = \'strict_all_tables\'');
});
......@@ -145,7 +149,6 @@ function rollback(connection, transactionError, callback) {
connection.rollback(function (error) {
if (error) debug('rollback: error when rolling back', error);
connection.removeAllListeners('error');
connection.release();
callback(transactionError);
......@@ -161,8 +164,6 @@ function transaction(queries, callback) {
beginTransaction(function (error, connection) {
if (error) return callback(error);
connection.on('error', callback);
async.mapSeries(queries, function iterator(query, done) {
connection.query(query.query, query.args, done);
}, function seriesDone(error, results) {
......@@ -171,7 +172,6 @@ function transaction(queries, callback) {
connection.commit(function (error) {
if (error) return rollback(connection, error, callback);
connection.removeAllListeners('error');
connection.release();
callback(null, results);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment