Skip to content

Commit

Permalink
call lock.TTL() with a timeout context
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan.rieckhof committed Nov 19, 2024
1 parent 7eef210 commit fc86408
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion maintenance/failover/failover.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,20 @@ func (a *ActivePassive) Run(ctx context.Context) error {

logger.Debug().Msg("Stefan: became active")

timeoutCtx, cancel := context.WithTimeout(ctx, 2*time.Second)

// Check TTL of the newly acquired lock and adjust refresh timer
ttl, err := lock.TTL(ctx)
ttl, err := lock.TTL(timeoutCtx)
if err != nil {
// If trying to get the TTL from the lock fails we become undefined and retry acquisition at the next tick.
logger.Debug().Err(err).Msg("Stefan: failed to get TTL from redis lock; becoming undefined")
cancel()
a.becomeUndefined(ctx)
continue
}

cancel()

logger.Debug().Msgf("Stefan: got TTL from redis lock: %v", ttl.Abs())

if ttl == 0 {
Expand Down

0 comments on commit fc86408

Please sign in to comment.