Skip to content

Commit

Permalink
fix(s3): always get a new S3 client for retries (#1534)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeDombo authored Oct 2, 2023
1 parent 8a08a8a commit 17494e9
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ protected long download(long rangeStart, long rangeEnd, MessageDigest messageDig
String bucket = s3ObjectPath.bucket;
String key = s3ObjectPath.key;

S3Client regionClient = getRegionClientForBucket(bucket);
GetObjectRequest getObjectRequest = GetObjectRequest.builder().bucket(bucket).key(key)
.range(String.format(HTTP_RANGE_HEADER_FORMAT, rangeStart, rangeEnd)).build();
logger.atDebug().kv("bucket", getObjectRequest.bucket()).kv("s3-key", getObjectRequest.key())
Expand All @@ -99,6 +98,7 @@ protected long download(long rangeStart, long rangeEnd, MessageDigest messageDig
try {
return RetryUtils.runWithRetry(s3ClientExceptionRetryConfig, () -> {
long downloaded = 0;
S3Client regionClient = getRegionClientForBucket(bucket);
try (InputStream inputStream = regionClient.getObject(getObjectRequest)) {
downloaded = download(inputStream, messageDigest);
if (downloaded == 0) {
Expand Down Expand Up @@ -148,11 +148,11 @@ public Long getDownloadSize() throws InterruptedException, PackageDownloadExcept
// Parse artifact path
String key = s3ObjectPath.key;
String bucket = s3ObjectPath.bucket;
S3Client regionClient = getRegionClientForBucket(bucket);
try {
HeadObjectRequest headObjectRequest = HeadObjectRequest.builder().bucket(bucket).key(key).build();
return RetryUtils.runWithRetry(s3ClientExceptionRetryConfig, () -> {
try {
S3Client regionClient = getRegionClientForBucket(bucket);
HeadObjectResponse headObjectResponse = regionClient.headObject(headObjectRequest);
return headObjectResponse.contentLength();
} catch (S3Exception e) {
Expand Down

0 comments on commit 17494e9

Please sign in to comment.