Skip to content

Commit edfc8d0

Browse files
authored
Merge pull request #1101 from Altinity/fix-optin-s3-regions
Antalya 25.8: Fix for opt-in AWS S3 regions when no explicit region is specified
2 parents c380e31 + 280d421 commit edfc8d0

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/IO/S3/Client.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,19 +703,35 @@ Client::doRequest(RequestType & request, RequestFn request_fn) const
703703
continue;
704704
}
705705

706-
if (error.GetResponseCode() != Aws::Http::HttpResponseCode::MOVED_PERMANENTLY)
706+
/// IllegalLocationConstraintException may indicate that we are working with an opt-in region (e.g. me-south-1)
707+
/// In that case, we need to update the region and try again
708+
bool is_illegal_constraint_exception = error.GetExceptionName() == "IllegalLocationConstraintException";
709+
if (error.GetResponseCode() != Aws::Http::HttpResponseCode::MOVED_PERMANENTLY && !is_illegal_constraint_exception)
707710
return result;
708711

709712
// maybe we detect a correct region
710-
if (!detect_region)
713+
bool new_region_detected = false;
714+
if (!detect_region || is_illegal_constraint_exception)
711715
{
712716
if (auto region = GetErrorMarshaller()->ExtractRegion(error); !region.empty() && region != explicit_region)
713717
{
718+
LOG_INFO(log, "Detected new region: {}", region);
714719
request.overrideRegion(region);
715720
insertRegionOverride(bucket, region);
721+
new_region_detected = true;
716722
}
717723
}
718724

725+
/// special handling for opt-in regions
726+
if (new_region_detected && is_illegal_constraint_exception && initial_endpoint.substr(11) == "amazonaws.com")
727+
{
728+
S3::URI new_uri(initial_endpoint);
729+
new_uri.addRegionToURI(request.getRegionOverride());
730+
found_new_endpoint = true;
731+
request.overrideURI(new_uri);
732+
continue;
733+
}
734+
719735
// we possibly got new location, need to try with that one
720736
auto new_uri = getURIFromError(error);
721737
if (!new_uri)

0 commit comments

Comments
 (0)