From c61e22cca68775a7fc019dceadda569345b7c063 Mon Sep 17 00:00:00 2001 From: Andrey Zvonov Date: Thu, 23 Oct 2025 20:45:10 +0200 Subject: [PATCH 1/3] handle opt-in regions properly --- src/IO/S3/Client.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/IO/S3/Client.cpp b/src/IO/S3/Client.cpp index 5fe470f9c19f..9d1a8bcbc824 100644 --- a/src/IO/S3/Client.cpp +++ b/src/IO/S3/Client.cpp @@ -703,22 +703,37 @@ Client::doRequest(RequestType & request, RequestFn request_fn) const continue; } - if (error.GetResponseCode() != Aws::Http::HttpResponseCode::MOVED_PERMANENTLY) + /// IllegalLocationConstraintException may indicate that we are working with an opt-in region (e.g. me-south-1) + /// In that case, we need to update the region and try again + if (error.GetResponseCode() != Aws::Http::HttpResponseCode::MOVED_PERMANENTLY && error.GetExceptionName() != "IllegalLocationConstraintException") return result; // maybe we detect a correct region - if (!detect_region) + bool new_region_detected = false; + if (!detect_region || error.GetExceptionName() == "IllegalLocationConstraintException") { if (auto region = GetErrorMarshaller()->ExtractRegion(error); !region.empty() && region != explicit_region) { + LOG_INFO(log, "Detected new region: {}", region); request.overrideRegion(region); insertRegionOverride(bucket, region); + new_region_detected = true; } } + /// special handling for opt-in regions + if (new_region_detected && error.GetExceptionName() == "IllegalLocationConstraintException" && initial_endpoint.substr(11) == "amazonaws.com") + { + S3::URI new_uri(initial_endpoint); + new_uri.addRegionToURI(request.getRegionOverride()); + found_new_endpoint = true; + request.overrideURI(new_uri); + continue; + } + // we possibly got new location, need to try with that one auto new_uri = getURIFromError(error); - if (!new_uri) + if (!new_uri && !new_region_detected) return result; if (initial_endpoint.substr(11) == "amazonaws.com") // Check if user didn't mention any region From 1673d729864885850acba988fd54173aee3d05a1 Mon Sep 17 00:00:00 2001 From: Andrey Zvonov Date: Thu, 23 Oct 2025 20:52:26 +0200 Subject: [PATCH 2/3] tiny fix --- src/IO/S3/Client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IO/S3/Client.cpp b/src/IO/S3/Client.cpp index 9d1a8bcbc824..90e910e3a29a 100644 --- a/src/IO/S3/Client.cpp +++ b/src/IO/S3/Client.cpp @@ -733,7 +733,7 @@ Client::doRequest(RequestType & request, RequestFn request_fn) const // we possibly got new location, need to try with that one auto new_uri = getURIFromError(error); - if (!new_uri && !new_region_detected) + if (!new_uri) return result; if (initial_endpoint.substr(11) == "amazonaws.com") // Check if user didn't mention any region From 280d4214db3ea8cb3d347ad2ff3a7ee3a648aa15 Mon Sep 17 00:00:00 2001 From: Andrey Zvonov Date: Fri, 24 Oct 2025 01:00:06 +0200 Subject: [PATCH 3/3] small improvements upd --- src/IO/S3/Client.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/IO/S3/Client.cpp b/src/IO/S3/Client.cpp index 90e910e3a29a..a248bfcd7382 100644 --- a/src/IO/S3/Client.cpp +++ b/src/IO/S3/Client.cpp @@ -705,12 +705,13 @@ Client::doRequest(RequestType & request, RequestFn request_fn) const /// IllegalLocationConstraintException may indicate that we are working with an opt-in region (e.g. me-south-1) /// In that case, we need to update the region and try again - if (error.GetResponseCode() != Aws::Http::HttpResponseCode::MOVED_PERMANENTLY && error.GetExceptionName() != "IllegalLocationConstraintException") + bool is_illegal_constraint_exception = error.GetExceptionName() == "IllegalLocationConstraintException"; + if (error.GetResponseCode() != Aws::Http::HttpResponseCode::MOVED_PERMANENTLY && !is_illegal_constraint_exception) return result; // maybe we detect a correct region bool new_region_detected = false; - if (!detect_region || error.GetExceptionName() == "IllegalLocationConstraintException") + if (!detect_region || is_illegal_constraint_exception) { if (auto region = GetErrorMarshaller()->ExtractRegion(error); !region.empty() && region != explicit_region) { @@ -722,7 +723,7 @@ Client::doRequest(RequestType & request, RequestFn request_fn) const } /// special handling for opt-in regions - if (new_region_detected && error.GetExceptionName() == "IllegalLocationConstraintException" && initial_endpoint.substr(11) == "amazonaws.com") + if (new_region_detected && is_illegal_constraint_exception && initial_endpoint.substr(11) == "amazonaws.com") { S3::URI new_uri(initial_endpoint); new_uri.addRegionToURI(request.getRegionOverride());