mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-02-07 05:49:05 +00:00
fix tests: wait for socket to send final responses
This commit is contained in:
parent
7075088848
commit
1b22b53fe8
@ -14,15 +14,18 @@ function Swarm (infoHash, server) {
|
|||||||
maxAge: server.peersCacheTtl || 20 * 60 * 1000 // 20 minutes
|
maxAge: server.peersCacheTtl || 20 * 60 * 1000 // 20 minutes
|
||||||
})
|
})
|
||||||
|
|
||||||
// When a peer is evicted from the LRU cache, if it's a websocket peer,
|
// When a websocket peer is evicted from the LRU cache, close the websocket
|
||||||
// close the websocket.
|
// after a short timeout period. We wait 1s so the server has a chance to send
|
||||||
|
// a response to 'stopped' events, which remove the peer and cause an eviction.
|
||||||
this.peers.on('evict', function (data) {
|
this.peers.on('evict', function (data) {
|
||||||
var peer = data.value
|
var peer = data.value
|
||||||
if (peer.socket) {
|
if (peer.socket) {
|
||||||
try {
|
setTimeout(function () {
|
||||||
peer.socket.close()
|
try {
|
||||||
peer.socket = null
|
peer.socket.close()
|
||||||
} catch (err) {}
|
peer.socket = null
|
||||||
|
} catch (err) {}
|
||||||
|
}, 1000)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user