mirror of
https://github.com/kubernetes/kubernetes.git
synced 2026-06-09 00:34:10 -04:00
Merge pull request #137694 from Jefftree/client-go-throttle-err
client-go: return context error directly instead of wrapping as rate limiter error
This commit is contained in:
commit
1fd96eb4bb
2 changed files with 16 additions and 1 deletions
|
|
@ -20,6 +20,7 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"encoding/hex"
|
||||
stderrors "errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"mime"
|
||||
|
|
@ -671,7 +672,8 @@ func (r *Request) tryThrottleWithInfo(ctx context.Context, retryInfo string) err
|
|||
now := time.Now()
|
||||
|
||||
err := r.rateLimiter.Wait(ctx)
|
||||
if err != nil {
|
||||
// Don't wrap context errors as caller initiated ctx cancellations is not a rate limiter error.
|
||||
if err != nil && !stderrors.Is(err, context.Canceled) && !stderrors.Is(err, context.DeadlineExceeded) {
|
||||
err = fmt.Errorf("client rate limiter Wait returned an error: %w", err)
|
||||
}
|
||||
latency := time.Since(now)
|
||||
|
|
|
|||
|
|
@ -4275,3 +4275,16 @@ func TestRequestWarningHandler(t *testing.T) {
|
|||
assert.Nil(t, request.warningHandler)
|
||||
})
|
||||
}
|
||||
|
||||
func TestTryThrottleWithInfoContextDeadline(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
||||
r := &Request{
|
||||
rateLimiter: flowcontrol.NewTokenBucketRateLimiter(1, 1),
|
||||
c: &RESTClient{base: &url.URL{Path: "/"}},
|
||||
}
|
||||
err := r.tryThrottleWithInfo(ctx, "")
|
||||
require.ErrorIs(t, err, context.Canceled)
|
||||
assert.NotContains(t, err.Error(), "client rate limiter")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue