From d0cdd53720276ee3499ff56ab1ce7d22601d8d9a Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sun, 27 Dec 2015 20:56:40 +0100 Subject: [PATCH] server: Fix persistent peers not being removed properly When a persistent peer is disconnected (for example due to a network timeout), a connection retry is issued. The logic for doing so failed to remove the peer from the peerState, causing dead peer connections to fill the peerState. Since connections in the peerState are counted towards the maxPeers limit, this would cause btcd to eventually stop retrying connection. This commit fixes the issue by properly removing the peer from the peerState. --- server.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/server.go b/server.go index 9ed3cca4..de1c584e 100644 --- a/server.go +++ b/server.go @@ -1124,12 +1124,10 @@ func (s *server) handleDonePeerMsg(state *peerState, sp *serverPeer) { // persistent outbound connection. if !sp.Inbound() && sp.persistent && atomic.LoadInt32(&s.shutdown) == 0 { // Retry peer - sp = s.newOutboundPeer(sp.Addr(), sp.persistent) - if sp != nil { - go s.retryConn(sp, false) + sp2 := s.newOutboundPeer(sp.Addr(), sp.persistent) + if sp2 != nil { + go s.retryConn(sp2, false) } - list[sp.ID()] = sp - return } if !sp.Inbound() && sp.VersionKnown() { state.outboundGroups[addrmgr.GroupKey(sp.NA())]--