database: do no reconnect in query
This commit is contained in:
@@ -66,6 +66,7 @@ function initialize(callback) {
|
||||
function uninitialize(callback) {
|
||||
if (gConnectionPool) {
|
||||
gConnectionPool.end(callback);
|
||||
gDefaultConnection = null;
|
||||
gConnectionPool = null;
|
||||
} else {
|
||||
callback(null);
|
||||
@@ -75,6 +76,8 @@ function uninitialize(callback) {
|
||||
function reconnect(callback) {
|
||||
callback = callback ? once(callback) : function () {};
|
||||
|
||||
debug('reconnect: connecting to database');
|
||||
|
||||
gConnectionPool.getConnection(function (error, connection) {
|
||||
if (error) {
|
||||
debug('reconnect: unable to reestablish connection to database. Try again in 10 seconds.', error.message);
|
||||
@@ -88,6 +91,8 @@ function reconnect(callback) {
|
||||
|
||||
debug('reconnect: unhandled mysql connection error. Will reconnect in 10 seconds', error);
|
||||
|
||||
gDefaultConnection = null;
|
||||
|
||||
// This is most likely an issue an can cause double callbacks from reconnect()
|
||||
setTimeout(reconnect.bind(null, callback), 10000);
|
||||
});
|
||||
@@ -153,15 +158,6 @@ function query() {
|
||||
|
||||
if (gDefaultConnection === null) return callback(new BoxError(BoxError.DATABASE_ERROR, 'No connection to database'));
|
||||
|
||||
args[args.length -1 ] = function (error, result) {
|
||||
if (error && error.fatal) {
|
||||
gDefaultConnection = null;
|
||||
setTimeout(reconnect, 1000);
|
||||
}
|
||||
|
||||
callback(error, result);
|
||||
};
|
||||
|
||||
gDefaultConnection.query.apply(gDefaultConnection, args);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user