File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed
Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments