Skip to content

Commit

Permalink
log and wait mechanism for setup errors
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Jan 1, 2021
1 parent 383197c commit 7fa3dad
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func unboundRunLoop(ctx context.Context, wg *sync.WaitGroup, settings models.Set
case !timer.Stop():
logger.Info("planned restart of unbound")
case setupErr != nil:
logger.Warn(setupErr)
logAndWait(ctx, logger, setupErr)
case firstRun:
logger.Info("restarting Unbound the first time to get updated files")
firstRun = false
Expand All @@ -187,6 +187,19 @@ func unboundRunLoop(ctx context.Context, wg *sync.WaitGroup, settings models.Set
}
}

func logAndWait(ctx context.Context, logger logging.Logger, err error) {
const wait = 10 * time.Second
logger.Error("%s, retrying in %s", err, wait)
timer := time.NewTimer(wait)
select {
case <-timer.C:
case <-ctx.Done():
if !timer.Stop() {
<-timer.C
}
}
}

func unboundRun(ctx, oldCtx context.Context, oldCancel context.CancelFunc,
timer *time.Timer, dnsConf dns.Configurator, settings models.Settings,
streamMerger command.StreamMerger,
Expand Down

0 comments on commit 7fa3dad

Please # to comment.