mirror of
https://github.com/kubernetes/client-go.git
synced 2026-07-21 15:55:55 +00:00
Merge pull request #140406 from tlplayer/fix-retry-context-canceled
client-go: preserve context cancellation in retry OnError Kubernetes-commit: 6d5610685c55faf1eab630ed7f6cd9f6d4accd13
This commit is contained in:
@@ -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