From d6a11bd3b048e0398908472dcfede207babf5946 Mon Sep 17 00:00:00 2001 From: behrad Date: Wed, 22 Jul 2015 12:14:08 +0430 Subject: [PATCH 1/3] bring retimer in for keep-alive rescheduling --- lib/client.js | 21 ++++++++++++--------- package.json | 1 + 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/client.js b/lib/client.js index 2c9fa5b..389e31e 100644 --- a/lib/client.js +++ b/lib/client.js @@ -26,6 +26,8 @@ OTHER DEALINGS IN THE SOFTWARE. var async = require("async"); +var retimer = require('retimer'); + function nop() {} /** @@ -150,10 +152,6 @@ Client.prototype._setup = function() { * @api private */ Client.prototype.setUpTimer = function() { - if (this.timer) { - clearTimeout(this.timer); - } - if (this.keepalive <= 0) { return; } @@ -163,10 +161,14 @@ Client.prototype.setUpTimer = function() { this.logger.debug({ timeout: timeout }, "setting keepalive timeout"); - this.timer = setTimeout(function() { - that.logger.info("keepalive timeout"); - that.onNonDisconnectClose(); - }, timeout); + if( this.timer ) { + this.timer.reschedule( timeout ); + } else { + this.timer = retimer(function keepaliveTimeout() { + that.logger.info("keepalive timeout"); + that.onNonDisconnectClose(); + }, timeout); + } }; /** @@ -538,7 +540,8 @@ Client.prototype.close = function(callback) { that.logger.debug("closing client"); if (this.timer) { - clearTimeout(this.timer); + //clearTimeout(this.timer); + this.timer.clear(); } } diff --git a/package.json b/package.json index 43e0858..e5e13e5 100644 --- a/package.json +++ b/package.json @@ -86,6 +86,7 @@ "msgpack5": "^1.3.0", "pbkdf2-password": "^1.0.0", "qlobber": "~0.5.0", + "retimer": "^1.0.1", "shortid": "^2.1.3", "st": "~0.5.1", "uglify-js": "^2.4.16", From 9b840e8e818237852f522532cbd769aebc98f4a4 Mon Sep 17 00:00:00 2001 From: behrad Date: Wed, 22 Jul 2015 12:36:20 +0430 Subject: [PATCH 2/3] remove clearTimeout --- lib/client.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/client.js b/lib/client.js index 9dfab9c..6413143 100644 --- a/lib/client.js +++ b/lib/client.js @@ -569,7 +569,6 @@ Client.prototype.close = function(callback) { that.logger.debug("closing client"); if (this.timer) { - //clearTimeout(this.timer); this.timer.clear(); } } From 85d4b5c43206d34a65d5c1c5d69419ae144adfce Mon Sep 17 00:00:00 2001 From: behrad Date: Wed, 22 Jul 2015 13:39:32 +0430 Subject: [PATCH 3/3] fix js linting --- lib/client.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/client.js b/lib/client.js index 6413143..8c99eeb 100644 --- a/lib/client.js +++ b/lib/client.js @@ -162,8 +162,8 @@ Client.prototype.setUpTimer = function() { this.logger.debug({ timeout: timeout }, "setting keepalive timeout"); - if( this.timer ) { - this.timer.reschedule( timeout ); + if (this.timer) { + this.timer.reschedule(timeout); } else { this.timer = retimer(function keepaliveTimeout() { that.logger.info("keepalive timeout");