From 1526772663b4c4224aa2226c55b87cb540c9df80 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 4 Dec 2020 21:39:50 +0300 Subject: [PATCH] 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. --- pkg/network/discovery.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/network/discovery.go b/pkg/network/discovery.go index b17c3a7ed..93781c045 100644 --- a/pkg/network/discovery.go +++ b/pkg/network/discovery.go @@ -232,15 +232,22 @@ func (d *DefaultDiscovery) run() { requested-- } 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 {