mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-04 08:35:10 +00:00
client-go/rest: backoff with context support
The BackoffManager interface sleeps without considering the caller's context, i.e. cancellation is not supported. This alone is reason enough to deprecate it and to replace it with an interface that supports a context parameter. The other reason is that contextual logging needs that parameter. Kubernetes-commit: b15a1943d51adfb8c5e0185d58d25e038c3d6ade
This commit is contained in:
committed by
Kubernetes Publisher
parent
2b2015d460
commit
7aa9904196
@@ -209,18 +209,18 @@ func (r *withRetry) Before(ctx context.Context, request *Request) error {
|
||||
// we do a backoff sleep before the first attempt is made,
|
||||
// (preserving current behavior).
|
||||
if request.backoff != nil {
|
||||
request.backoff.Sleep(request.backoff.CalculateBackoff(url))
|
||||
request.backoff.SleepWithContext(ctx, request.backoff.CalculateBackoffWithContext(ctx, url))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// if we are here, we have made attempt(s) at least once before.
|
||||
if request.backoff != nil {
|
||||
delay := request.backoff.CalculateBackoff(url)
|
||||
delay := request.backoff.CalculateBackoffWithContext(ctx, url)
|
||||
if r.retryAfter.Wait > delay {
|
||||
delay = r.retryAfter.Wait
|
||||
}
|
||||
request.backoff.Sleep(delay)
|
||||
request.backoff.SleepWithContext(ctx, delay)
|
||||
}
|
||||
|
||||
// We are retrying the request that we already send to
|
||||
@@ -258,9 +258,9 @@ func (r *withRetry) After(ctx context.Context, request *Request, resp *http.Resp
|
||||
|
||||
if request.c.base != nil {
|
||||
if err != nil {
|
||||
request.backoff.UpdateBackoff(request.URL(), err, 0)
|
||||
request.backoff.UpdateBackoffWithContext(ctx, request.URL(), err, 0)
|
||||
} else {
|
||||
request.backoff.UpdateBackoff(request.URL(), err, resp.StatusCode)
|
||||
request.backoff.UpdateBackoffWithContext(ctx, request.URL(), err, resp.StatusCode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user