Skip to content

Commit

Permalink
use distinct context for initial sync
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Peterson <[email protected]>
  • Loading branch information
captncraig committed Jul 11, 2023
1 parent ce4709a commit 69dbe09
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pkg/reloader/reloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,15 @@ func (r *Reloader) Watch(ctx context.Context) error {
}

defer runutil.CloseWithLogOnErr(r.logger, r.watcher, "config watcher close")
applyCtx, applyCancel := context.WithTimeout(ctx, r.watchInterval)

if r.cfgFile != "" {
if err := r.watcher.addFile(r.cfgFile); err != nil {
return errors.Wrapf(err, "add config file %s to watcher", r.cfgFile)
}

if err := r.apply(applyCtx); err != nil {
initialSyncCtx, initialSyncCancel := context.WithTimeout(ctx, r.watchInterval)
err := r.apply(initialSyncCtx)
initialSyncCancel()
if err != nil {
return err
}
}
Expand Down Expand Up @@ -239,9 +240,7 @@ func (r *Reloader) Watch(ctx context.Context) error {
"out", r.cfgOutputFile,
"dirs", strings.Join(r.watchedDirs, ","))

// Reset the watch timeout.
applyCancel()
applyCtx, applyCancel = context.WithTimeout(ctx, r.watchInterval)
applyCtx, applyCancel := context.WithTimeout(ctx, r.watchInterval)

for {
select {
Expand Down

0 comments on commit 69dbe09

Please sign in to comment.