From 59bd8b3dfa4f2e55da477d9e8d8a91f1924287cf Mon Sep 17 00:00:00 2001 From: Kenneth Jenkins <51246568+kenjenkins@users.noreply.github.com> Date: Wed, 15 Nov 2023 14:03:22 -0800 Subject: [PATCH] zero/reconciler: fix restart behavior (#4753) Currently the RunWithRestart() loop may not exit when execFn returns an error unrelated to its context cancellation. Add an additional check for this case. --- internal/zero/reconciler/restart.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/zero/reconciler/restart.go b/internal/zero/reconciler/restart.go index 079b09302..0154214e4 100644 --- a/internal/zero/reconciler/restart.go +++ b/internal/zero/reconciler/restart.go @@ -2,14 +2,15 @@ package reconciler import ( "context" + "errors" "fmt" "sync" ) // RunWithRestart executes execFn. -// The execution would be restarted, by means of canceling the context provided to execFn, each time restartFn quits. +// The execution would be restarted, by means of canceling the context provided to execFn, each time restartFn returns. // the error returned by restartFn is purely informational and does not affect the execution; may be nil. -// the loop is stopped when the context provided to RunWithRestart is canceled or a genuine error is returned by execFn, not caused by the context. +// the loop is stopped when the context provided to RunWithRestart is canceled or execFn returns an error unrelated to its context cancellation. func RunWithRestart( ctx context.Context, execFn func(context.Context) error, @@ -64,7 +65,7 @@ func restartWithContext( var err error for ctx := range contexts { err = execFn(ctx) - if ctx.Err() == nil { + if ctx.Err() == nil || !errors.Is(err, ctx.Err()) { return err } }