From 85f19936dd6899172512074b3b312200fcd0fe81 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 12 Sep 2019 16:29:50 +0300 Subject: [PATCH] network: implement connection retries It's worth to try a bit more than once. --- pkg/network/discovery.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pkg/network/discovery.go b/pkg/network/discovery.go index 2f44d5ddf..7b9f4d20d 100644 --- a/pkg/network/discovery.go +++ b/pkg/network/discovery.go @@ -6,6 +6,7 @@ import ( const ( maxPoolSize = 200 + connRetries = 3 ) // Discoverer is an interface that is responsible for maintaining @@ -25,7 +26,7 @@ type DefaultDiscovery struct { dialTimeout time.Duration addrs map[string]bool badAddrs map[string]bool - unconnectedAddrs map[string]bool + unconnectedAddrs map[string]int requestCh chan int connectedCh chan string backFill chan string @@ -40,7 +41,7 @@ func NewDefaultDiscovery(dt time.Duration, ts Transporter) *DefaultDiscovery { dialTimeout: dt, addrs: make(map[string]bool), badAddrs: make(map[string]bool), - unconnectedAddrs: make(map[string]bool), + unconnectedAddrs: make(map[string]int), requestCh: make(chan int), connectedCh: make(chan string), backFill: make(chan string), @@ -143,12 +144,17 @@ func (d *DefaultDiscovery) run() { } if _, ok := d.addrs[addr]; !ok { d.addrs[addr] = true - d.unconnectedAddrs[addr] = true + d.unconnectedAddrs[addr] = connRetries d.pool <- addr } case addr := <-d.badAddrCh: - d.badAddrs[addr] = true - delete(d.unconnectedAddrs, addr) + d.unconnectedAddrs[addr]-- + if d.unconnectedAddrs[addr] > 0 { + d.pool <- addr + } else { + d.badAddrs[addr] = true + delete(d.unconnectedAddrs, addr) + } d.RequestRemote(1) case addr := <-d.connectedCh: