Skip to content

Commit

Permalink
Code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
myleshorton committed Nov 22, 2024
1 parent 81ffa60 commit fef9cd5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
21 changes: 10 additions & 11 deletions dialer/fastconnect.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func newFastConnectDialer(opts *Options, next func(opts *Options, existing Diale
opts: opts,
next: next,
topDialer: protectedDialer{},
stopCh: make(chan struct{}),
stopCh: make(chan struct{}, 10),
}
}

Expand Down Expand Up @@ -113,21 +113,21 @@ func (fcd *fastConnectDialer) connectAll(dialers []ProxyDialer) {
return
}
log.Debugf("Dialing all dialers in parallel %#v", dialers)
outerLoop:
for {
// Loop until we're connected
if len(fcd.connected.dialers) < 2 {
fcd.parallelDial(dialers)
// Add jitter to avoid thundering herd
time.Sleep(time.Duration(rand.Intn(4000)) * time.Millisecond)
} else {
break
}
select {
case <-fcd.stopCh:
log.Debug("Stopping parallel dialing")
return
default:
// Loop until we're connected
if len(fcd.connected.dialers) < 2 {
fcd.parallelDial(dialers)
// Add jitter to avoid thundering herd
time.Sleep(time.Duration(rand.Intn(4000)) * time.Millisecond)
} else {
break outerLoop
}

}
}
// At this point, we've tried all of the dialers, and they've all either
Expand All @@ -138,7 +138,6 @@ outerLoop:
nextOpts := fcd.opts.Clone()
nextOpts.Dialers = fcd.connected.proxyDialers()
fcd.next(nextOpts, fcd)

}

func (fcd *fastConnectDialer) parallelDial(dialers []ProxyDialer) {
Expand Down
1 change: 0 additions & 1 deletion dialer/two_phase_dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func NewTwoPhaseDialer(opts *Options, next func(opts *Options, existing Dialer)
// This is where we move to the second dialer.
nextDialer := next(dialerOpts, existing)
tpd.activeDialer.set(nextDialer)
existing.Close()
return nextDialer
})

Expand Down

0 comments on commit fef9cd5

Please sign in to comment.