Skip to content

Commit 059c677

Browse files
author
Víctor Oliva
committed
Add maximum retries to polling after network error.
1 parent 477e30d commit 059c677

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/transport/lib/polling.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function Polling(Receiver, receiveUrl, AjaxObject) {
1515
this.Receiver = Receiver;
1616
this.receiveUrl = receiveUrl;
1717
this.AjaxObject = AjaxObject;
18+
this.networkRetries = 0;
1819
this._scheduleReceiver();
1920
}
2021

@@ -26,6 +27,7 @@ Polling.prototype._scheduleReceiver = function() {
2627
var poll = this.poll = new this.Receiver(this.receiveUrl, this.AjaxObject);
2728

2829
poll.on('message', function(msg) {
30+
self.networkRetries = 0;
2931
debug('message', msg);
3032
self.emit('message', msg);
3133
});
@@ -35,7 +37,8 @@ Polling.prototype._scheduleReceiver = function() {
3537
self.poll = poll = null;
3638

3739
if (!self.pollIsClosing) {
38-
if (reason === 'network') {
40+
if (reason === 'network' && self.networkRetries < Polling.NETWORK_RETRIES) {
41+
self.networkRetries++;
3942
self._scheduleReceiver();
4043
} else {
4144
self.emit('close', code || 1006, reason);
@@ -54,4 +57,6 @@ Polling.prototype.abort = function() {
5457
}
5558
};
5659

60+
Polling.NETWORK_RETRIES = 3;
61+
5762
module.exports = Polling;

0 commit comments

Comments
 (0)