network: drop requests to discovery pool when it can't be handled

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.
This commit is contained in:
Roman Khimov 2020-12-04 21:39:50 +03:00
parent 972b0f176d
commit 1526772663

View file

@ -232,15 +232,22 @@ func (d *DefaultDiscovery) run() {
requested-- requested--
} }
default: // Empty pool default: // Empty pool
var added int
d.lock.Lock() d.lock.Lock()
for _, addr := range d.seeds { for _, addr := range d.seeds {
if !d.connectedAddrs[addr] { if !d.connectedAddrs[addr] {
delete(d.badAddrs, addr) delete(d.badAddrs, addr)
d.unconnectedAddrs[addr] = connRetries d.unconnectedAddrs[addr] = connRetries
d.pushToPoolOrDrop(addr) d.pushToPoolOrDrop(addr)
added++
} }
} }
d.lock.Unlock() 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 { if !ok {