Skip to content

Commit

Permalink
server: defer cancelling the outbound connection until the tie-breaker
Browse files Browse the repository at this point in the history
  • Loading branch information
Roasbeef committed Jun 9, 2018
1 parent 7b4f66b commit e62f862
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions server.go
Expand Up @@ -1621,7 +1621,7 @@ func (s *server) InboundPeerConnected(conn net.Conn) {
// If we already have an outbound connection to this peer, then ignore
// this new connection.
if _, ok := s.outboundPeers[pubStr]; ok {
srvrLog.Debugf("Already have outbound connection for %v, "+
srvrLog.Debugf("Already have outbound connection for %x, "+
"ignoring inbound connection", nodePub.SerializeCompressed())

conn.Close()
Expand All @@ -1639,12 +1639,6 @@ func (s *server) InboundPeerConnected(conn net.Conn) {

srvrLog.Infof("New inbound connection from %v", conn.RemoteAddr())

// Cancel all pending connection requests, we either already have an
// outbound connection, or this incoming connection will become our
// primary connection. The incoming connection will not have an
// associated connection request, so we pass nil.
s.cancelConnReqs(pubStr, nil)

// Check to see if we already have a connection with this peer. If so,
// we may need to drop our existing connection. This prevents us from
// having duplicate connections to the same peer. We forgo adding a
Expand All @@ -1655,6 +1649,7 @@ func (s *server) InboundPeerConnected(conn net.Conn) {
case ErrPeerNotConnected:
// We were unable to locate an existing connection with the
// target peer, proceed to connect.
s.cancelConnReqs(pubStr, nil)
s.peerConnected(conn, nil, true)

case nil:
Expand All @@ -1676,6 +1671,8 @@ func (s *server) InboundPeerConnected(conn net.Conn) {
srvrLog.Debugf("Disconnecting stale connection to %v",
connectedPeer)

s.cancelConnReqs(pubStr, nil)

// Remove the current peer from the server's internal state and
// signal that the peer termination watcher does not need to
// execute for this peer.
Expand Down Expand Up @@ -1706,7 +1703,7 @@ func (s *server) OutboundPeerConnected(connReq *connmgr.ConnReq, conn net.Conn)
// If we already have an inbound connection to this peer, then ignore
// this new connection.
if _, ok := s.inboundPeers[pubStr]; ok {
srvrLog.Debugf("Already have inbound connection for %v, "+
srvrLog.Debugf("Already have inbound connection for %x, "+
"ignoring outbound connection",
nodePub.SerializeCompressed())

Expand Down

0 comments on commit e62f862

Please sign in to comment.