Skip to content

Commit 3041b3c

Browse files
committed
Add timeout on http requests for kv store DynamoDB client
Signed-off-by: Anna Tran <[email protected]>
1 parent 582c03a commit 3041b3c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

pkg/ring/lifecycler.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ func (i *Lifecycler) loop(ctx context.Context) error {
468468
// We are jittering for at least half of the time and max the time of the heartbeat.
469469
// If we jitter too soon, we can have problems of concurrency with autoJoin leaving the instance on ACTIVE without tokens
470470
time.AfterFunc(time.Duration(uint64(i.cfg.HeartbeatPeriod/2)+uint64(mathrand.Int63())%uint64(i.cfg.HeartbeatPeriod/2)), func() {
471-
i.heartbeat()
471+
i.heartbeat(ctx)
472472
heartbeatTicker.Reset(i.cfg.HeartbeatPeriod)
473473
})
474474
defer heartbeatTicker.Stop()
@@ -530,7 +530,7 @@ func (i *Lifecycler) loop(ctx context.Context) error {
530530
}
531531

532532
case <-heartbeatTickerChan:
533-
i.heartbeat()
533+
i.heartbeat(ctx)
534534
case f := <-i.actorChan:
535535
f()
536536

@@ -541,8 +541,9 @@ func (i *Lifecycler) loop(ctx context.Context) error {
541541
}
542542
}
543543

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

0 commit comments

Comments
 (0)