Clear reconnect timeout on destroy

This commit is contained in:
Yoann Ciabaud 2016-03-16 09:22:33 +01:00 committed by Feross Aboukhadijeh
parent 35e6eeaef2
commit 3252070328

View File

@ -87,6 +87,7 @@ WebSocketTracker.prototype.destroy = function (cb) {
if (self.destroyed) return cb(null)
self.destroyed = true
clearInterval(self.interval)
clearTimeout(self.reconnectTimer)
if (socketPool[self.announceUrl]) socketPool[self.announceUrl].consumers--
@ -299,11 +300,11 @@ 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
var reconnectTimer = setTimeout(function () {
self.reconnectTimer = setTimeout(function () {
self.retries++
self._openSocket()
}, ms)
if (reconnectTimer.unref) reconnectTimer.unref()
if (self.reconnectTimer.unref) self.reconnectTimer.unref()
debug('reconnecting socket in %s ms', ms)
}