From b67b73604c789fab097fa4116131fd082dc1a563 Mon Sep 17 00:00:00 2001 From: vyzo Date: Wed, 31 Mar 2021 20:04:42 +0300 Subject: [PATCH] don't add backoff if we have successfully connected for consistency with the old dialer behaviour. --- swarm_dial.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/swarm_dial.go b/swarm_dial.go index 513ce1c..1a5cb12 100644 --- a/swarm_dial.go +++ b/swarm_dial.go @@ -368,7 +368,8 @@ func (s *Swarm) dialWorkerLoop(ctx context.Context, p peer.ID, reqch <-chan Dial var nextDial []ma.Multiaddr active := 0 - done := false + done := false // true when the request channel has been closed + connected := false // true when a connection has been successfully established resch := make(chan dialResult) @@ -509,6 +510,10 @@ loop: case res := <-resch: active-- + if res.Conn != nil { + connected = true + } + if done && active == 0 { if res.Conn != nil { // we got an actual connection, but the dial has been cancelled @@ -556,7 +561,9 @@ loop: } // it must be an error -- add backoff if applicable and dispatch - if res.Err != context.Canceled { + if res.Err != context.Canceled && !connected { + // we only add backoff if there has not been a successful connection + // for consistency with the old dialer behavior. s.backf.AddBackoff(p, res.Addr) } -- GitLab