added web3 connection attempts limit
This commit is contained in:
parent
a7ffc8aa1e
commit
d68696f329
15
lib/node.js
15
lib/node.js
@ -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');
|
||||
if(this._connection_attempts < MAX_CONNECTION_ATTEMPTS)
|
||||
{
|
||||
console.error('Web3 connection attempt', chalk.cyan('#' + this._connection_attempts++), 'failed');
|
||||
console.info('Trying again in', 500 * this._connection_attempts)
|
||||
|
||||
setTimeout(function ()
|
||||
{
|
||||
self.checkWeb3Connection();
|
||||
}, 500);
|
||||
}, 500 * this._connection_attempts);
|
||||
}
|
||||
else
|
||||
{
|
||||
console.error('Web3 connection failed', MAX_CONNECTION_ATTEMPTS, 'times. Aborting...');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user