Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Clear reconnect timeout on destroy
  • Loading branch information
yciabaud committed Mar 16, 2016
commit c7a5367e7d0b35d5905ecf1db498fafe2ca084dc
5 changes: 3 additions & 2 deletions lib/client/websocket-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ WebSocketTracker.prototype.destroy = function (cb) {
if (self.destroyed) return cb(null)
self.destroyed = true
clearInterval(self.interval)
clearTimeout(self.reconnectTimer)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good idea!


if (socketPool[self.announceUrl]) socketPool[self.announceUrl].consumers--
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer -= 1 to --


Expand Down Expand Up @@ -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 () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add self.reconnectTimer = null to the constructor, as a form of "documentation".

self.retries++
self._openSocket()
}, ms)
if (reconnectTimer.unref) reconnectTimer.unref()
if (self.reconnectTimer.unref) self.reconnectTimer.unref()

debug('reconnecting socket in %s ms', ms)
}
Expand Down