From e2116e4c3f678ffe0aff56ffe0349a4e31296be3 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 24 Feb 2020 12:39:46 +0300 Subject: [PATCH] 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. --- pkg/network/server.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/network/server.go b/pkg/network/server.go index dacac6461..3e0eb6575 100644 --- a/pkg/network/server.go +++ b/pkg/network/server.go @@ -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()