+7
-7
@@ -17,6 +17,7 @@ var assert = require('assert'),
|
||||
BoxError = require('./boxerror.js'),
|
||||
child_process = require('child_process'),
|
||||
constants = require('./constants.js'),
|
||||
debug = require('debug')('box:database'),
|
||||
mysql = require('mysql'),
|
||||
once = require('once'),
|
||||
util = require('util');
|
||||
@@ -76,7 +77,7 @@ function reconnect(callback) {
|
||||
|
||||
gConnectionPool.getConnection(function (error, connection) {
|
||||
if (error) {
|
||||
console.error('Unable to reestablish connection to database. Try again in 10 seconds.', error.message);
|
||||
debug('reconnect: unable to reestablish connection to database. Try again in 10 seconds.', error.message);
|
||||
return setTimeout(reconnect.bind(null, callback), 10000);
|
||||
}
|
||||
|
||||
@@ -85,7 +86,7 @@ function reconnect(callback) {
|
||||
// this function should be invoked only when we have no callbacks pending and we have a fatal error
|
||||
assert(error.fatal, 'Non-fatal error on connection object');
|
||||
|
||||
console.error('Unhandled mysql connection error. Will reconnect in 10 seconds', error);
|
||||
debug('reconnect: unhandled mysql connection error. Will reconnect in 10 seconds', error);
|
||||
|
||||
// This is most likely an issue an can cause double callbacks from reconnect()
|
||||
setTimeout(reconnect.bind(null, callback), 10000);
|
||||
@@ -123,23 +124,22 @@ function beginTransaction(callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function rollback(connection, callback) {
|
||||
function rollback(connection, commitError, callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
connection.rollback(function (error) {
|
||||
if (error) console.error(error); // can this happen?
|
||||
if (error) debug('rollback: error when rolloing back', error);
|
||||
|
||||
connection.release();
|
||||
callback(null);
|
||||
callback(commitError);
|
||||
});
|
||||
}
|
||||
|
||||
// FIXME: if commit fails, is it supposed to return an error ?
|
||||
function commit(connection, callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
connection.commit(function (error) {
|
||||
if (error) return rollback(connection, callback);
|
||||
if (error) return rollback(connection, error, callback);
|
||||
|
||||
connection.release();
|
||||
return callback(null);
|
||||
|
||||
Reference in New Issue
Block a user