Skip to content

Commit

Permalink
Add maximum retries to polling after network error.
Browse files Browse the repository at this point in the history
  • Loading branch information
voliva committed Feb 13, 2019
1 parent 477e30d commit 059c677
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/transport/lib/polling.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function Polling(Receiver, receiveUrl, AjaxObject) {
this.Receiver = Receiver;
this.receiveUrl = receiveUrl;
this.AjaxObject = AjaxObject;
this.networkRetries = 0;
this._scheduleReceiver();
}

Expand All @@ -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);
});
Expand All @@ -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);
Expand All @@ -54,4 +57,6 @@ Polling.prototype.abort = function() {
}
};

Polling.NETWORK_RETRIES = 3;

module.exports = Polling;

0 comments on commit 059c677

Please sign in to comment.