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.
This commit is contained in:
Olaoluwa Osuntokun 2017-04-11 21:14:38 -07:00
parent 35c9a12a73
commit a22ba92630
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
1 changed files with 2 additions and 2 deletions

View File

@ -644,7 +644,7 @@ func (s *server) inboundPeerConnected(conn net.Conn) {
} }
s.pendingConnMtx.RUnlock() 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 // 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 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 // addPeer adds the passed peer to the server's global state of all active