Skip to content

Commit da28219

Browse files
authored
Merge pull request #78 from Mytherin/fixinitonrefresh
Continue in S3FileHandle::Initialize on secret refresh
2 parents ab43cb5 + 77b5207 commit da28219

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

extension/httpfs/s3fs.cpp

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -720,8 +720,8 @@ void S3FileHandle::Initialize(optional_ptr<FileOpener> opener) {
720720
HTTPFileHandle::Initialize(opener);
721721
} catch (std::exception &ex) {
722722
ErrorData error(ex);
723+
bool refreshed_secret = false;
723724
if (error.Type() == ExceptionType::IO || error.Type() == ExceptionType::HTTP) {
724-
bool refreshed_secret = false;
725725
auto context = opener->TryGetClientContext();
726726
if (context) {
727727
auto transaction = CatalogTransaction::GetSystemCatalogTransaction(*context);
@@ -732,30 +732,28 @@ void S3FileHandle::Initialize(optional_ptr<FileOpener> opener) {
732732
}
733733
}
734734
}
735-
736-
if (refreshed_secret) {
737-
// We have succesfully refreshed a secret: retry initializing with new credentials
738-
FileOpenerInfo info = {path};
739-
auth_params = S3AuthParams::ReadFrom(opener, info);
740-
HTTPFileHandle::Initialize(opener);
741-
return;
742-
}
743735
}
744-
auto &extra_info = error.ExtraInfo();
745-
auto entry = extra_info.find("status_code");
746-
if (entry != extra_info.end()) {
747-
if (entry->second == "400") {
748-
// 400: BAD REQUEST
749-
auto extra_text = S3FileSystem::GetS3BadRequestError(auth_params);
750-
throw Exception(error.Type(), error.RawMessage() + extra_text, extra_info);
751-
}
752-
if (entry->second == "403") {
753-
// 403: FORBIDDEN
754-
auto extra_text = S3FileSystem::GetS3AuthError(auth_params);
755-
throw Exception(error.Type(), error.RawMessage() + extra_text, extra_info);
736+
if (!refreshed_secret) {
737+
auto &extra_info = error.ExtraInfo();
738+
auto entry = extra_info.find("status_code");
739+
if (entry != extra_info.end()) {
740+
if (entry->second == "400") {
741+
// 400: BAD REQUEST
742+
auto extra_text = S3FileSystem::GetS3BadRequestError(auth_params);
743+
throw Exception(error.Type(), error.RawMessage() + extra_text, extra_info);
744+
}
745+
if (entry->second == "403") {
746+
// 403: FORBIDDEN
747+
auto extra_text = S3FileSystem::GetS3AuthError(auth_params);
748+
throw Exception(error.Type(), error.RawMessage() + extra_text, extra_info);
749+
}
756750
}
751+
throw;
757752
}
758-
throw;
753+
// We have succesfully refreshed a secret: retry initializing with new credentials
754+
FileOpenerInfo info = {path};
755+
auth_params = S3AuthParams::ReadFrom(opener, info);
756+
HTTPFileHandle::Initialize(opener);
759757
}
760758

761759
auto &s3fs = file_system.Cast<S3FileSystem>();

0 commit comments

Comments
 (0)