From 69dbe09462d6cd845121e34509060d7980e64678 Mon Sep 17 00:00:00 2001 From: Craig Peterson <192540+captncraig@users.noreply.github.com> Date: Tue, 11 Jul 2023 14:46:34 -0400 Subject: [PATCH] use distinct context for initial sync Signed-off-by: Craig Peterson <192540+captncraig@users.noreply.github.com> --- pkg/reloader/reloader.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/reloader/reloader.go b/pkg/reloader/reloader.go index fb8ed418f5..2057ea5f75 100644 --- a/pkg/reloader/reloader.go +++ b/pkg/reloader/reloader.go @@ -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 } } @@ -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 {