From d68696f329df1f966ad19d8825025b6a9da9f5df Mon Sep 17 00:00:00 2001 From: cubedro Date: Wed, 13 May 2015 16:39:29 +0300 Subject: [PATCH 1/2] added web3 connection attempts limit --- lib/node.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) 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...'); + } } } } From 7858bda654b4301ebb1303dfae3173e40ece8680 Mon Sep 17 00:00:00 2001 From: cubedro Date: Wed, 13 May 2015 16:46:47 +0300 Subject: [PATCH 2/2] a bit of styling for new changes --- lib/node.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node.js b/lib/node.js index f94770f..d43bc3f 100644 --- a/lib/node.js +++ b/lib/node.js @@ -151,7 +151,7 @@ Node.prototype.checkWeb3Connection = function() 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) + console.error('Trying again in', chalk.cyan(500 * this._connection_attempts + ' ms')); setTimeout(function () { @@ -160,7 +160,7 @@ Node.prototype.checkWeb3Connection = function() } else { - console.error('Web3 connection failed', MAX_CONNECTION_ATTEMPTS, 'times. Aborting...'); + console.error('Web3 connection failed', chalk.cyan(MAX_CONNECTION_ATTEMPTS), 'times. Aborting...'); } } }