guard against self.socket being null

This commit is contained in:
Feross Aboukhadijeh 2016-03-18 23:12:28 -07:00
parent e1da561022
commit db868cac78

View File

@ -95,10 +95,12 @@ WebSocketTracker.prototype.destroy = function (cb) {
clearInterval(self.interval)
clearTimeout(self.reconnectTimer)
self.socket.removeListener('connect', self._onSocketConnectBound)
self.socket.removeListener('data', self._onSocketDataBound)
self.socket.removeListener('close', self._onSocketCloseBound)
self.socket.removeListener('error', self._onSocketErrorBound)
if (self.socket) {
self.socket.removeListener('connect', self._onSocketConnectBound)
self.socket.removeListener('data', self._onSocketDataBound)
self.socket.removeListener('close', self._onSocketCloseBound)
self.socket.removeListener('error', self._onSocketErrorBound)
}
self._onSocketConnectBound = null
self._onSocketErrorBound = null
@ -120,9 +122,8 @@ WebSocketTracker.prototype.destroy = function (cb) {
if (socketPool[self.announceUrl].consumers === 0) {
delete socketPool[self.announceUrl]
self.socket.on('error', noop) // ignore all future errors
try {
self.socket.on('error', noop) // ignore all future errors
self.socket.destroy(cb)
} catch (err) {
cb(null)