Skip to content

Commit

Permalink
recreate context if context deadline exceeded
Browse files Browse the repository at this point in the history
  • Loading branch information
samos123 committed Feb 4, 2024
1 parent 4b2acd8 commit c149556
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/leader/election.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,18 @@ func (le *Election) Start(ctx context.Context) {
for {
select {
case <-ctx.Done():
return
if ctx.Err() == context.DeadlineExceeded {
ctx = context.Background()
} else {
return
}
default:
if retryCount > 0 {
backoff.Next(backoffID, backoff.Clock.Now())
delay := backoff.Get(backoffID)
log.Printf("Leader election failed, retrying in %v. RetryCount: %v", delay, retryCount+1)
select {
case <-time.After(delay):
case <-ctx.Done():
return
}
}
log.Printf("Starting leader election process. RetryCount: %v", retryCount+1)
Expand Down

0 comments on commit c149556

Please sign in to comment.