Skip to content

Commit 6fe41ac

Browse files
authored
S3 bucket: Don't retry when ctx cancel (#5997)
* s3: no need to retry and wait when last error is context cancel or deadline exceeded Signed-off-by: Ben Ye <[email protected]> * add tests Signed-off-by: Ben Ye <[email protected]> * lint Signed-off-by: Ben Ye <[email protected]> --------- Signed-off-by: Ben Ye <[email protected]>
1 parent 35732c3 commit 6fe41ac

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

pkg/storage/bucket/s3/bucket_client.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/go-kit/log"
1010
"github.com/go-kit/log/level"
11+
"github.com/pkg/errors"
1112
"github.com/prometheus/common/model"
1213
"github.com/thanos-io/objstore"
1314
"github.com/thanos-io/objstore/providers/s3"
@@ -127,6 +128,10 @@ func (b *BucketWithRetries) retry(ctx context.Context, f func() error, operation
127128
if lastErr == nil {
128129
return nil
129130
}
131+
// No need to retry when context was already canceled.
132+
if errors.Is(lastErr, context.Canceled) || errors.Is(lastErr, context.DeadlineExceeded) {
133+
return lastErr
134+
}
130135
if b.bucket.IsObjNotFoundErr(lastErr) || b.bucket.IsAccessDeniedErr(lastErr) {
131136
return lastErr
132137
}

pkg/storage/bucket/s3/bucket_client_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ func TestBucketWithRetries_ShouldRetry(t *testing.T) {
3434
err: errKeyDenied,
3535
retryCount: 1,
3636
},
37+
"should not retry when context canceled": {
38+
err: context.Canceled,
39+
retryCount: 1,
40+
},
41+
"should not retry when context deadline exceeded": {
42+
err: context.DeadlineExceeded,
43+
retryCount: 1,
44+
},
3745
}
3846

3947
for name, tc := range cases {

0 commit comments

Comments
 (0)