mirror of
https://github.com/kubernetes/client-go.git
synced 2026-07-20 22:49:15 +00:00
client-go: preserve context cancellation in retry OnError
OnError replaced context cancellation errors with a nil lastErr when the error was non-retriable. Preserve the callback error when no retriable error was recorded. Add a regression test covering a context cancellation returned on the first invocation. Kubernetes-commit: 23b344cd1581a871984e44be951249af6018242e
This commit is contained in:
committed by
Kubernetes Publisher
parent
8c9ee70637
commit
7a574b0397
@@ -59,7 +59,7 @@ func OnError(backoff wait.Backoff, retriable func(error) bool, fn func() error)
|
||||
return false, err
|
||||
}
|
||||
})
|
||||
if wait.Interrupted(err) {
|
||||
if wait.Interrupted(err) && lastErr != nil {
|
||||
err = lastErr
|
||||
}
|
||||
return err
|
||||
|
||||
@@ -17,6 +17,8 @@ limitations under the License.
|
||||
package retry
|
||||
|
||||
import (
|
||||
"context"
|
||||
stderrors "errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
@@ -69,3 +71,12 @@ func TestRetryOnConflict(t *testing.T) {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRetryOnConflictPreservesContextErrorWithoutLastError(t *testing.T) {
|
||||
err := RetryOnConflict(DefaultBackoff, func() error {
|
||||
return context.Canceled
|
||||
})
|
||||
if !stderrors.Is(err, context.Canceled) {
|
||||
t.Fatalf("expected context.Canceled, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user