added web3 connection attempts limit

This commit is contained in:
cubedro 2015-05-13 16:39:29 +03:00
parent a7ffc8aa1e
commit d68696f329

View File

@ -34,6 +34,7 @@ var UPDATE_INTERVAL = 5000;
var PING_INTERVAL = 2000; var PING_INTERVAL = 2000;
var MINERS_LIMIT = 5; var MINERS_LIMIT = 5;
var MAX_HISTORY_UPDATE = 50; var MAX_HISTORY_UPDATE = 50;
var MAX_CONNECTION_ATTEMPTS = 10;
Socket = Primus.createSocket({ Socket = Primus.createSocket({
transformer: 'websockets', transformer: 'websockets',
@ -109,7 +110,7 @@ function Node ()
this._lastChainLog = 0; this._lastChainLog = 0;
this._lastPendingLog = 0; this._lastPendingLog = 0;
this._called = 0 this._connection_attempts = 0
this.startWeb3Connection(); this.startWeb3Connection();
@ -147,12 +148,20 @@ Node.prototype.checkWeb3Connection = function()
} }
catch (err) catch (err)
{ {
console.error('Web3 connection attempt', chalk.cyan('#' + this._called++), 'failed'); if(this._connection_attempts < MAX_CONNECTION_ATTEMPTS)
setTimeout(function ()
{ {
self.checkWeb3Connection(); console.error('Web3 connection attempt', chalk.cyan('#' + this._connection_attempts++), 'failed');
}, 500); console.info('Trying again in', 500 * this._connection_attempts)
setTimeout(function ()
{
self.checkWeb3Connection();
}, 500 * this._connection_attempts);
}
else
{
console.error('Web3 connection failed', MAX_CONNECTION_ATTEMPTS, 'times. Aborting...');
}
} }
} }
} }