Merge pull request #132 from cubedro/develop

Web3 connection attempts limit
This commit is contained in:
Marian OANCΞA 2015-05-13 16:57:13 +03:00
commit b2201c19f9
1 changed files with 15 additions and 6 deletions

View File

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