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.
This commit is contained in:
Kenneth Jenkins 2023-11-15 14:03:22 -08:00 committed by GitHub
parent 3c2dc5e0a2
commit 59bd8b3dfa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,14 +2,15 @@ package reconciler
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"sync" "sync"
) )
// RunWithRestart executes execFn. // 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 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( func RunWithRestart(
ctx context.Context, ctx context.Context,
execFn func(context.Context) error, execFn func(context.Context) error,
@ -64,7 +65,7 @@ func restartWithContext(
var err error var err error
for ctx := range contexts { for ctx := range contexts {
err = execFn(ctx) err = execFn(ctx)
if ctx.Err() == nil { if ctx.Err() == nil || !errors.Is(err, ctx.Err()) {
return err return err
} }
} }