database: do no reconnect in query

This commit is contained in:
Girish Ramakrishnan
2020-06-03 16:28:30 -07:00
parent 45d5f8c74d
commit aae49f16a2

View File

@@ -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);
}