From 059c677eef10f427ff3afed1d5a9887d530e4aef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Oliva?= Date: Wed, 13 Feb 2019 15:42:18 +0100 Subject: [PATCH] Add maximum retries to polling after network error. --- lib/transport/lib/polling.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/transport/lib/polling.js b/lib/transport/lib/polling.js index 8108432b..42a763ed 100644 --- a/lib/transport/lib/polling.js +++ b/lib/transport/lib/polling.js @@ -15,6 +15,7 @@ function Polling(Receiver, receiveUrl, AjaxObject) { this.Receiver = Receiver; this.receiveUrl = receiveUrl; this.AjaxObject = AjaxObject; + this.networkRetries = 0; this._scheduleReceiver(); } @@ -26,6 +27,7 @@ Polling.prototype._scheduleReceiver = function() { var poll = this.poll = new this.Receiver(this.receiveUrl, this.AjaxObject); poll.on('message', function(msg) { + self.networkRetries = 0; debug('message', msg); self.emit('message', msg); }); @@ -35,7 +37,8 @@ Polling.prototype._scheduleReceiver = function() { self.poll = poll = null; if (!self.pollIsClosing) { - if (reason === 'network') { + if (reason === 'network' && self.networkRetries < Polling.NETWORK_RETRIES) { + self.networkRetries++; self._scheduleReceiver(); } else { self.emit('close', code || 1006, reason); @@ -54,4 +57,6 @@ Polling.prototype.abort = function() { } }; +Polling.NETWORK_RETRIES = 3; + module.exports = Polling;