Skip to content

Commit

Permalink
Defer cancel on timeout for heartbeat
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Tran <[email protected]>
  • Loading branch information
anna-tran committed Sep 17, 2024
1 parent 3041b3c commit c6a3ca9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/ring/lifecycler.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,9 @@ func (i *Lifecycler) loop(ctx context.Context) error {

func (i *Lifecycler) heartbeat(ctx context.Context) {
i.lifecyclerMetrics.consulHeartbeats.Inc()
ctx, _ = context.WithTimeout(ctx, i.cfg.HeartbeatPeriod)
if err := i.updateConsul(context.Background()); err != nil {
ctx, cancel := context.WithTimeout(ctx, i.cfg.HeartbeatPeriod)
defer cancel()
if err := i.updateConsul(ctx); err != nil {
level.Error(i.logger).Log("msg", "failed to write to the KV store, sleeping", "ring", i.RingName, "err", err)
}
}
Expand Down

0 comments on commit c6a3ca9

Please sign in to comment.