Skip to content

Commit

Permalink
Lower retry interval on dns resolve failure (#2176)
Browse files Browse the repository at this point in the history
  • Loading branch information
lixmal authored Jun 24, 2024
1 parent eaa31c2 commit 628673d
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions client/internal/routemanager/dynamic/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import (
const (
DefaultInterval = time.Minute

minInterval = 2 * time.Second
minInterval = 2 * time.Second
failureInterval = 5 * time.Second

addAllowedIP = "add allowed IP %s: %w"
)
Expand Down Expand Up @@ -160,25 +161,41 @@ func (r *Route) startResolver(ctx context.Context) {
ticker := time.NewTicker(interval)
defer ticker.Stop()

r.update(ctx)
if err := r.update(ctx); err != nil {
log.Errorf("Failed to resolve domains for route [%v]: %v", r, err)
if interval > failureInterval {
ticker.Reset(failureInterval)
}
}

for {
select {
case <-ctx.Done():
log.Debugf("Stopping dynamic route resolver for domains [%v]", r)
return
case <-ticker.C:
r.update(ctx)
if err := r.update(ctx); err != nil {
log.Errorf("Failed to resolve domains for route [%v]: %v", r, err)
// Use a lower ticker interval if the update fails
if interval > failureInterval {
ticker.Reset(failureInterval)
}
} else if interval > failureInterval {
// Reset to the original interval if the update succeeds
ticker.Reset(interval)
}
}
}
}

func (r *Route) update(ctx context.Context) {
func (r *Route) update(ctx context.Context) error {
if resolved, err := r.resolveDomains(); err != nil {
log.Errorf("Failed to resolve domains for route [%v]: %v", r, err)
return fmt.Errorf("resolve domains: %w", err)
} else if err := r.updateDynamicRoutes(ctx, resolved); err != nil {
log.Errorf("Failed to update dynamic routes for [%v]: %v", r, err)
return fmt.Errorf("update dynamic routes: %w", err)
}

return nil
}

func (r *Route) resolveDomains() (domainMap, error) {
Expand Down

0 comments on commit 628673d

Please sign in to comment.