Skip to content

Commit b2c2b8f

Browse files
committed
do not access socket.infoHashes if socket is destroyed
1 parent 40707a1 commit b2c2b8f

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

lib/server/swarm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Swarm.prototype._onAnnounceStopped = function (params, peer, id) {
102102

103103
// If it's a websocket, remove this swarm's infohash from the list of active
104104
// swarms that this peer is participating in.
105-
if (peer.socket) {
105+
if (peer.socket && !peer.socket.destroyed) {
106106
var index = peer.socket.infoHashes.indexOf(this.infoHash)
107107
arrayRemove(peer.socket.infoHashes, index)
108108
}

server.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ Server.prototype._onWebSocketRequest = function (socket, opts, params) {
491491
if (!socket.peerId) socket.peerId = params.peer_id // as hex
492492

493493
self._onRequest(params, function (err, response) {
494-
if (self.destroyed) return
494+
if (self.destroyed || socket.destroyed) return
495495
if (err) {
496496
socket.send(JSON.stringify({
497497
action: params.action === common.ACTIONS.ANNOUNCE ? 'announce' : 'scrape',
@@ -587,6 +587,7 @@ Server.prototype._onWebSocketSend = function (socket, err) {
587587
Server.prototype._onWebSocketClose = function (socket) {
588588
var self = this
589589
debug('websocket close %s', socket.peerId)
590+
socket.destroyed = true
590591

591592
if (socket.peerId) {
592593
socket.infoHashes.slice(0).forEach(function (infoHash) {

0 commit comments

Comments
 (0)