Skip to content

Commit

Permalink
fix(dot/network): findPeers returns on timeout if a peer is found (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Dec 13, 2022
1 parent 8320a2d commit 2a05ce7
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions dot/network/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,14 @@ func (d *discovery) advertise() {
}

func (d *discovery) checkPeerCount() {
timer := time.NewTicker(connectToPeersTimeout)
defer timer.Stop()
ticker := time.NewTicker(connectToPeersTimeout)
defer ticker.Stop()

for {
select {
case <-d.ctx.Done():
return
case <-timer.C:
case <-ticker.C:
if len(d.h.Network().Peers()) > d.minPeers {
continue
}
Expand Down Expand Up @@ -217,10 +217,6 @@ func (d *discovery) findPeers() {
logger.Tracef("found new peer %s via DHT", peer.ID)
d.h.Peerstore().AddAddrs(peer.ID, peer.Addrs, peerstore.PermanentAddrTTL)
d.handler.AddPeer(0, peer.ID)

if !timer.Stop() {
<-timer.C
}
}
}
}
Expand Down

0 comments on commit 2a05ce7

Please sign in to comment.