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.
This commit is contained in:
Dario Nieuwenhuis 2015-12-27 20:56:40 +01:00
parent 89af747603
commit d0cdd53720

View file

@ -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())]--