Skip to content

Commit

Permalink
connmgr: Only mark persistent peer reconn pending.
Browse files Browse the repository at this point in the history
The current code is incorrectly treating non-persistent peer requests as
though they will be reconnected to whenever the target number of
outbound peers has not been reached by marking them as pending and
logging the reconnection attempt that will never come.  In addition to
the spurious logging, it also means that manually attempting to
reconnect to such a peer will incorrectly believe a connection is
already pending.

This resolves that issue by only logging the attempt and adding the
connection request back to the pending map for persistent peers.
  • Loading branch information
davecgh committed May 2, 2024
1 parent 249a205 commit 02eaf5f
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions connmgr/connmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,19 +379,21 @@ out:
continue
}

// Otherwise, we will attempt a reconnection if
// we do not have enough peers, or if this is a
// persistent peer. The connection request is
// re added to the pending map, so that
// subsequent processing of connections and
// failures do not ignore the request.
if uint32(len(conns)) < cm.cfg.TargetOutbound ||
connReq.Permanent {

connReq.updateState(ConnPending)
log.Debugf("Reconnecting to %v",
connReq)
pending[msg.id] = connReq
// Otherwise, attempt a reconnection when there are not already
// enough outbound peers to satisfy the target number of
// outbound peers or this is a persistent peer.
numConns := uint32(len(conns))
if numConns < cm.cfg.TargetOutbound || connReq.Permanent {
// The connection request is reused for persistent peers, so
// add it back to the pending map in that case so that
// subsequent processing of connections and failures do not
// ignore the request.
if connReq.Permanent {
connReq.updateState(ConnPending)
log.Debugf("Reconnecting to %v", connReq)
pending[msg.id] = connReq
}

cm.handleFailedConn(ctx, connReq)
}

Expand Down

0 comments on commit 02eaf5f

Please sign in to comment.