Skip to content

Commit

Permalink
use safetimer and log retry interval
Browse files Browse the repository at this point in the history
  • Loading branch information
schmichael committed Sep 29, 2023
1 parent 8411fe1 commit 9463896
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions client/allocwatcher/alloc_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,28 +374,32 @@ func (p *remotePrevAlloc) Wait(ctx context.Context) error {
resp := structs.SingleAllocResponse{}
err := p.rpc.RPC("Alloc.GetAlloc", &req, &resp)
if err != nil {
p.logger.Error("error querying previous alloc", "error", err)
retry := getRemoteRetryIntv + helper.RandomStagger(getRemoteRetryIntv)
timer, stop := helper.NewSafeTimer(retry)
p.logger.Error("error querying previous alloc", "error", err, "wait", retry)
select {
case <-time.After(retry):
case <-timer.C:
continue
case <-ctx.Done():
stop()
return ctx.Err()
}
}

// Ensure that we didn't receive a stale response
if req.AllowStale && resp.Index < req.MinQueryIndex {
retry := getRemoteRetryIntv + helper.RandomStagger(getRemoteRetryIntv)
timer, stop := helper.NewSafeTimer(retry)
p.logger.Warn("received stale alloc; retrying",
"req_index", req.MinQueryIndex,
"resp_index", resp.Index,
"wait", retry,
)
select {
case <-time.After(retry):
case <-timer.C:
continue
case <-ctx.Done():
stop()
return ctx.Err()
}
}
Expand Down

0 comments on commit 9463896

Please sign in to comment.