diff --git a/lib/node.js b/lib/node.js index f24568a..f94770f 100644 --- a/lib/node.js +++ b/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'); - - setTimeout(function () + if(this._connection_attempts < MAX_CONNECTION_ATTEMPTS) { - self.checkWeb3Connection(); - }, 500); + 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 * this._connection_attempts); + } + else + { + console.error('Web3 connection failed', MAX_CONNECTION_ATTEMPTS, 'times. Aborting...'); + } } } }