Skip to content

Commit

Permalink
server: eliminate possibly deadlock, peerConnected now async
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Roasbeef committed Apr 12, 2017
1 parent 35c9a12 commit a22ba92
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit a22ba92

Please sign in to comment.