network: don't deadlock on connection overflow

(*Peer).Disconnect send an unregister signal to this goroutine, so invoking it
from here is not a good idea, run it asynchronously.
This commit is contained in:
Roman Khimov 2020-02-24 12:39:46 +03:00
parent cad1f074d4
commit e2116e4c3f

View file

@ -226,7 +226,8 @@ func (s *Server) run() {
s.lock.RLock()
// Pick a random peer and drop connection to it.
for peer := range s.peers {
peer.Disconnect(errMaxPeers)
// It will send us unregister signal.
go peer.Disconnect(errMaxPeers)
break
}
s.lock.RUnlock()