Skip to content

Commit

Permalink
network: drop requests to discovery pool when it can't be handled
Browse files Browse the repository at this point in the history
It happens from time to time in a four-node private network where there are
seeds (aka CNs) and not a lot of other nodes to connect to.

I don't know how to test for an infinite loop that has no side-effects, so no
test added here.
  • Loading branch information
roman-khimov committed Jun 18, 2021
1 parent 9d6439b commit 38d14d4
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/network/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,22 @@ func (d *DefaultDiscovery) run() {
}
d.lock.Unlock()
default: // Empty pool
var added int
d.lock.Lock()
for _, addr := range d.seeds {
if !d.connectedAddrs[addr] {
delete(d.badAddrs, addr)
d.unconnectedAddrs[addr] = connRetries
d.pushToPoolOrDrop(addr)
added++
}
}
d.lock.Unlock()
// The pool is empty, but all seed nodes are already connected,
// we can end up in an infinite loop here, so drop the request.
if added == 0 {
requested = 0
}
}
}
if !ok {
Expand Down

0 comments on commit 38d14d4

Please sign in to comment.