Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
don't add backoff if we have successfully connected
Browse files Browse the repository at this point in the history
for consistency with the old dialer behaviour.
  • Loading branch information
vyzo committed Mar 31, 2021
1 parent 699b4d1 commit b67b736
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions swarm_dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit b67b736

Please sign in to comment.