mirror of
https://github.com/pomerium/pomerium.git
synced 2025-04-28 18:06:34 +02:00
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:
parent
3c2dc5e0a2
commit
59bd8b3dfa
1 changed files with 4 additions and 3 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue