From a22ba926301c33a1932db86a7d11057ec335ca86 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 11 Apr 2017 21:14:38 -0700 Subject: [PATCH] server: eliminate possibly deadlock, peerConnected now async This commit eliminates a possible deadlock (or repeated peer connection failures) that can arise due to the [inbound|outbound]PeerConnected methods holding the peer mutex too long. We now alleviate this concurrency issue by calling s.peerConnected in an asynchronous manner. This is safe as all operations within the method are themselves goroutine-safe. --- server.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server.go b/server.go index 481a8801..5efb702e 100644 --- a/server.go +++ b/server.go @@ -644,7 +644,7 @@ func (s *server) inboundPeerConnected(conn net.Conn) { } s.pendingConnMtx.RUnlock() - s.peerConnected(conn, nil, false) + go s.peerConnected(conn, nil, false) } // outboundPeerConnected initializes a new peer in response to a new outbound @@ -669,7 +669,7 @@ func (s *server) outboundPeerConnected(connReq *connmgr.ConnReq, conn net.Conn) return } - s.peerConnected(conn, connReq, true) + go s.peerConnected(conn, connReq, true) } // addPeer adds the passed peer to the server's global state of all active