From 89b9fb7f400e1cb3591a1fa4ff782ccba737e483 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Fri, 18 Mar 2016 23:14:48 -0700 Subject: [PATCH] prevent two reconnect timers for running at same time --- lib/client/websocket-tracker.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/client/websocket-tracker.js b/lib/client/websocket-tracker.js index 177e889..cb3608d 100644 --- a/lib/client/websocket-tracker.js +++ b/lib/client/websocket-tracker.js @@ -29,6 +29,7 @@ function WebSocketTracker (client, announceUrl, opts) { self.peers = {} // peers (offer id -> peer) self.socket = null + self.reconnecting = false self.retries = 0 self.reconnectTimer = null @@ -91,7 +92,9 @@ WebSocketTracker.prototype.destroy = function (cb) { var self = this if (!cb) cb = noop if (self.destroyed) return cb(null) + self.destroyed = true + clearInterval(self.interval) clearTimeout(self.reconnectTimer) @@ -319,6 +322,7 @@ WebSocketTracker.prototype._startReconnectTimer = function () { var ms = Math.floor(Math.random() * RECONNECT_VARIANCE) + Math.min(Math.pow(2, self.retries) * RECONNECT_MINIMUM, RECONNECT_MAXIMUM) self.reconnecting = true + clearTimeout(self.reconnectTimer) self.reconnectTimer = setTimeout(function () { self.retries++ self._openSocket()