Skip to content

Commit

Permalink
Added polling to wait group
Browse files Browse the repository at this point in the history
  • Loading branch information
zasweq committed Mar 19, 2021
1 parent 3ea54b9 commit 69eb649
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions internal/resolver/dns/dns_resolver.go
Expand Up @@ -213,26 +213,28 @@ func (d *dnsResolver) poll(errorFromClientConn error) {
}
p := make(chan struct{})
d.polling = p
// This exponential backoff go routine will be running at most once
// This exponential backoff go routine will be running at most once.
d.wg.Add(1)
go func() {
defer d.wg.Done()
// Exponentially backoff until it hopefully succeeds.
for i := 0; ; i++ {
t := newTimer(backoff.DefaultExponential.Backoff(i))
select {
case <-p:
// Polling was successful
// Polling was successful.
t.Stop()
return
case <-d.ctx.Done():
return
case <-t.C:
select {
case <-p:
// Polling was successful
// Polling was successful.
return
default:
}
// Timer expired; re-resolve
// Timer expired; re-resolve.
}
// After select for testing purposes. Forcing a re-resolution would cause many tests to be flaky.
// This allows a re-resolution to be guarded by the resolveNowBackoff() function, which can be toggled
Expand Down

0 comments on commit 69eb649

Please sign in to comment.