Skip to content

Commit

Permalink
Don't update domains if context is cancelled
Browse files Browse the repository at this point in the history
  • Loading branch information
lixmal committed Jun 3, 2024
1 parent 7fa931c commit 81b93e2
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions client/internal/routemanager/dynamic/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,29 +160,28 @@ func (r *Route) startResolver(ctx context.Context) {
ticker := time.NewTicker(interval)
defer ticker.Stop()

r.update()
r.update(ctx)

for {
select {
case <-ctx.Done():
log.Debugf("Stopping dynamic route resolver for domains [%v]", r)
return
case <-ticker.C:
r.update()
r.update(ctx)
}
}
}

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

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

results := make(chan resolveResult)
go r.resolve(results)

Expand Down Expand Up @@ -227,10 +226,15 @@ func (r *Route) resolve(results chan resolveResult) {
close(results)
}

func (r *Route) updateDynamicRoutes(newDomains domainMap) error {
func (r *Route) updateDynamicRoutes(ctx context.Context, newDomains domainMap) error {
r.mu.Lock()
defer r.mu.Unlock()

if ctx.Err() != nil {
log.Debugf("Not updating dynamic routes for domains [%v] because context is done", r)
return nil

Check failure on line 235 in client/internal/routemanager/dynamic/route.go

View workflow job for this annotation

GitHub Actions / lint (macos-latest)

error is not nil (line 233) but it returns nil (nilerr)
}

var merr *multierror.Error

for domain, newPrefixes := range newDomains {
Expand Down

0 comments on commit 81b93e2

Please sign in to comment.