@@ -49,6 +49,7 @@ function Server (opts) {
4949 if ( typeof opts . filter === 'function' ) self . _filter = opts . filter
5050
5151 self . listening = false
52+ self . destroyed = false
5253 self . torrents = { }
5354
5455 self . http = null
@@ -148,6 +149,7 @@ Server.prototype.close = function (cb) {
148149 debug ( 'close' )
149150
150151 self . listening = false
152+ self . destroyed = true
151153
152154 if ( self . udp4 ) {
153155 try {
@@ -212,7 +214,7 @@ Server.prototype.onHttpRequest = function (req, res, opts) {
212214 'failure reason' : err . message
213215 }
214216 }
215- if ( ! self . listening ) return
217+ if ( self . destroyed ) return
216218
217219 delete response . action // only needed for UDP encoding
218220 res . end ( bencode . encode ( response ) )
@@ -243,7 +245,7 @@ Server.prototype.onUdpRequest = function (msg, rinfo) {
243245 'failure reason' : err . message
244246 }
245247 }
246- if ( ! self . listening ) return
248+ if ( self . destroyed ) return
247249
248250 response . transactionId = params . transactionId
249251 response . connectionId = params . connectionId
@@ -299,7 +301,7 @@ Server.prototype._onWebSocketRequest = function (socket, params) {
299301 'failure reason' : err . message
300302 }
301303 }
302- if ( ! self . listening ) return
304+ if ( self . destroyed ) return
303305
304306 if ( socket . infoHashes . indexOf ( params . info_hash ) === - 1 ) {
305307 socket . infoHashes . push ( params . info_hash )
0 commit comments