mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-01-18 20:21:36 +00:00
guard against self.socket being null
This commit is contained in:
parent
e1da561022
commit
db868cac78
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user