Skip to content

Commit 1b22b53

Browse files
committed
fix tests: wait for socket to send final responses
1 parent 7075088 commit 1b22b53

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/server/swarm.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@ function Swarm (infoHash, server) {
1414
maxAge: server.peersCacheTtl || 20 * 60 * 1000 // 20 minutes
1515
})
1616

17-
// When a peer is evicted from the LRU cache, if it's a websocket peer,
18-
// close the websocket.
17+
// When a websocket peer is evicted from the LRU cache, close the websocket
18+
// after a short timeout period. We wait 1s so the server has a chance to send
19+
// a response to 'stopped' events, which remove the peer and cause an eviction.
1920
this.peers.on('evict', function (data) {
2021
var peer = data.value
2122
if (peer.socket) {
22-
try {
23-
peer.socket.close()
24-
peer.socket = null
25-
} catch (err) {}
23+
setTimeout(function () {
24+
try {
25+
peer.socket.close()
26+
peer.socket = null
27+
} catch (err) {}
28+
}, 1000)
2629
}
2730
})
2831
}

0 commit comments

Comments
 (0)