From 55a7d7b332f1fe4072f1c874fca8ff0a192113ef Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Fri, 30 Jun 2023 14:29:24 -0400 Subject: [PATCH] fix: reduce timeout and increase minimum backoff time --- waku/v2/discovery_connector.go | 11 ++++------- waku/v2/node/wakunode2.go | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/waku/v2/discovery_connector.go b/waku/v2/discovery_connector.go index aaed82e7..18724621 100644 --- a/waku/v2/discovery_connector.go +++ b/waku/v2/discovery_connector.go @@ -202,9 +202,6 @@ func (c *PeerConnectionStrategy) publishWork(ctx context.Context, p peer.AddrInf case c.dialCh <- p: case <-ctx.Done(): return - case <-time.After(1 * time.Second): - // This timeout is to not lock the goroutine - return } } @@ -261,6 +258,10 @@ func (c *PeerConnectionStrategy) dialPeers(ctx context.Context) { continue } + if c.host.Network().Connectedness(pi.ID) == network.Connected { + continue + } + c.mux.Lock() val, ok := c.cache.Get(pi.ID) var cachedPeer *connCacheData @@ -280,10 +281,6 @@ func (c *PeerConnectionStrategy) dialPeers(ctx context.Context) { } c.mux.Unlock() - if c.host.Network().Connectedness(pi.ID) == network.Connected { - continue - } - dialCtx, dialCtxCancel := context.WithTimeout(c.workerCtx, c.dialTimeout) err := c.host.Connect(dialCtx, pi) if err != nil && !errors.Is(err, context.Canceled) { diff --git a/waku/v2/node/wakunode2.go b/waku/v2/node/wakunode2.go index 462c1352..a9e2a6fe 100644 --- a/waku/v2/node/wakunode2.go +++ b/waku/v2/node/wakunode2.go @@ -244,9 +244,9 @@ func New(opts ...WakuNodeOption) (*WakuNode, error) { // Setup peer connection strategy cacheSize := 600 rngSrc := rand.NewSource(rand.Int63()) - minBackoff, maxBackoff := time.Second*30, time.Hour + minBackoff, maxBackoff := time.Minute, time.Hour bkf := backoff.NewExponentialBackoff(minBackoff, maxBackoff, backoff.FullJitter, time.Second, 5.0, 0, rand.New(rngSrc)) - w.peerConnector, err = v2.NewPeerConnectionStrategy(cacheSize, w.opts.discoveryMinPeers, network.DialPeerTimeout, bkf, w.log) + w.peerConnector, err = v2.NewPeerConnectionStrategy(cacheSize, w.opts.discoveryMinPeers, 20*time.Second, bkf, w.log) if err != nil { w.log.Error("creating peer connection strategy", zap.Error(err)) }