mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-01-31 02:21:36 +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
|
||||
})
|
||||
|
||||
// When a peer is evicted from the LRU cache, if it's a websocket peer,
|
||||
// close the websocket.
|
||||
// When a websocket peer is evicted from the LRU cache, 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) {
|
||||
var peer = data.value
|
||||
if (peer.socket) {
|
||||
try {
|
||||
peer.socket.close()
|
||||
peer.socket = null
|
||||
} catch (err) {}
|
||||
setTimeout(function () {
|
||||
try {
|
||||
peer.socket.close()
|
||||
peer.socket = null
|
||||
} catch (err) {}
|
||||
}, 1000)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user