From 02eaf5f3109717fe5278bec03d96c5c0eef8cd79 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Tue, 30 Apr 2024 10:01:49 -0500 Subject: [PATCH] connmgr: Only mark persistent peer reconn pending. 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. --- connmgr/connmanager.go | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/connmgr/connmanager.go b/connmgr/connmanager.go index 1e66da868c..6bcc35fd9d 100644 --- a/connmgr/connmanager.go +++ b/connmgr/connmanager.go @@ -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) }