Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
lippserd committed Apr 10, 2024
1 parent d7957b0 commit fc00fa9
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions pkg/icingadb/ha.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (h *HA) controller() {
// expiration time. Therefore, we use a deadline ctx to retry.WithBackoff() in realize() which expires earlier
// than our default timeout.
// 2) Since we do not want to exit before our default timeout expires, we have to repeat step 1 until it does.
retryTimeout := time.NewTicker(retry.DefaultTimeout)
retryTimeout := time.NewTimer(retry.DefaultTimeout)
defer retryTimeout.Stop()

for {
Expand All @@ -179,7 +179,7 @@ func (h *HA) controller() {
h.realizeLostHeartbeat()

// Reset retry timeout so that the next iterations have the full amount of time available again.
retryTimeout.Reset(retry.DefaultTimeout)
resetTimer(h.ctx, retryTimeout, retry.DefaultTimeout)

continue
}
Expand Down Expand Up @@ -251,7 +251,7 @@ func (h *HA) controller() {
// But this is the best place to catch all scenarios where the timeout needs to be reset.
// And since HA needs quite a bit of refactoring anyway to e.g. return immediately after calling h.abort(),
// it's fine to have it here for now.
retryTimeout.Reset(retry.DefaultTimeout)
resetTimer(h.ctx, retryTimeout, retry.DefaultTimeout)
case <-h.heartbeat.Done():
if err := h.heartbeat.Err(); err != nil {
h.abort(err)
Expand Down Expand Up @@ -528,3 +528,14 @@ func (h *HA) signalTakeover(reason string) {
}
}
}

func resetTimer(ctx context.Context, t *time.Timer, d time.Duration) {
if !t.Stop() {
select {
case <-t.C:
case <-ctx.Done():
return
}
}
t.Reset(d)
}

0 comments on commit fc00fa9

Please sign in to comment.