Skip to content

Commit c6a3ca9

Browse files
committed
Defer cancel on timeout for heartbeat
Signed-off-by: Anna Tran <[email protected]>
1 parent 3041b3c commit c6a3ca9

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

pkg/ring/lifecycler.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,9 @@ func (i *Lifecycler) loop(ctx context.Context) error {
543543

544544
func (i *Lifecycler) heartbeat(ctx context.Context) {
545545
i.lifecyclerMetrics.consulHeartbeats.Inc()
546-
ctx, _ = context.WithTimeout(ctx, i.cfg.HeartbeatPeriod)
547-
if err := i.updateConsul(context.Background()); err != nil {
546+
ctx, cancel := context.WithTimeout(ctx, i.cfg.HeartbeatPeriod)
547+
defer cancel()
548+
if err := i.updateConsul(ctx); err != nil {
548549
level.Error(i.logger).Log("msg", "failed to write to the KV store, sleeping", "ring", i.RingName, "err", err)
549550
}
550551
}

0 commit comments

Comments
 (0)