zero: simplify control loop lease retry code (#4979)

zero: simplify lease control loop
This commit is contained in:
Denis Mishin 2024-03-01 11:36:08 -05:00 committed by GitHub
parent a2bf995642
commit d405a53b90
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 213 deletions

View file

@ -5,6 +5,7 @@ import (
"context"
"time"
"github.com/cenkalti/backoff/v4"
"golang.org/x/sync/errgroup"
"github.com/pomerium/pomerium/pkg/grpc/databroker"
@ -23,7 +24,7 @@ func (c *service) GetDataBrokerServiceClient() databroker.DataBrokerServiceClien
// RunLeased implements the databroker.LeaseHandler interface.
func (c *service) RunLeased(ctx context.Context) error {
eg, ctx := errgroup.WithContext(ctx)
for _, fn := range c.funcs {
for _, fn := range append(c.funcs, c.databrokerChangeMonitor) {
fn := fn
eg.Go(func() error {
return fn(ctx)
@ -42,8 +43,11 @@ func Run(
client: client,
funcs: funcs,
}
b := backoff.NewExponentialBackOff()
b.MaxElapsedTime = 0
leaser := databroker.NewLeaser("zero-ctrl", time.Second*30, srv)
return RunWithRestart(ctx, func(ctx context.Context) error {
return leaser.Run(ctx)
}, srv.databrokerChangeMonitor)
return backoff.Retry(
func() error { return leaser.Run(ctx) },
backoff.WithContext(b, ctx),
)
}