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