From db868cac780a89d2933ad7c8878d742790d9b942 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Fri, 18 Mar 2016 23:12:28 -0700 Subject: [PATCH] guard against self.socket being null --- lib/client/websocket-tracker.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/client/websocket-tracker.js b/lib/client/websocket-tracker.js index 3ad80e1..36033c8 100644 --- a/lib/client/websocket-tracker.js +++ b/lib/client/websocket-tracker.js @@ -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)