retry: abort retry loop on context errors (#1383)

Fixes #1377
This commit is contained in:
Jarek Kowalski authored and GitHub committed 2021-10-13 19:10:02 -07:00
1 parent befaac501b
commit b7a4fa56bf
2 files changed
+20

No files matched your search

+5
View File
@@ -56,6 +56,11 @@ func internalRetry(ctx context.Context, desc string, attempt AttemptFunc, isRetr
var lastError error
for i := 0; i < count; i++ {
if cerr := ctx.Err(); cerr != nil {
// nolint:wrapcheck
return nil, cerr
}
v, err := attempt()
if err == nil {
return v, nil
+15
View File
@@ -1,10 +1,12 @@
package retry
import (
"context"
"testing"
"time"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
"github.com/kopia/kopia/internal/testlogging"
)
@@ -58,3 +60,16 @@ func TestRetry(t *testing.T) {
})
}
}
func TestRetryContextCancel(t *testing.T) {
t.Parallel()
ctx := testlogging.Context(t)
canceledctx, cancel := context.WithCancel(ctx)
cancel()
require.ErrorIs(t, context.Canceled, WithExponentialBackoffNoValue(canceledctx, "canceled", func() error {
return errRetriable
}, isRetriable))
}