raulcd commented on code in PR #55881:
URL: https://github.com/apache/arrow/pull/55881#discussion_r4766690354


##########
cpp/src/arrow/filesystem/s3fs.cc:
##########
@@ -921,11 +968,27 @@ class S3ClientFinalizer : public 
std::enable_shared_from_this<S3ClientFinalizer>
     return holder;
   }
 
+  void AddCredentialsProvider(
+      const std::shared_ptr<FinalizableCredentialsProvider>& provider) {
+    std::unique_lock lock(mutex_);
+    if (finalized_) {
+      lock.unlock();
+      provider->Finalize();
+      return;
+    }
+    auto end = std::remove_if(
+        providers_.begin(), providers_.end(),
+        [](std::weak_ptr<FinalizableCredentialsProvider> p) { return 
p.expired(); });
+    providers_.erase(end, providers_.end());

Review Comment:
   nit: I think this could be simplified as we required C++ 20 now but we would 
require `#include <vector>` too. We can follow up this simplification pattern 
afterwards as we could do with client too and this PR shouldn't grow more.
   
   ```suggestion
       std::erase_if(providers_, [](const auto& p) { return p.expired(); });
   ```



##########
cpp/src/arrow/filesystem/s3fs.cc:
##########
@@ -900,8 +908,47 @@ class S3ClientHolder {
   std::shared_ptr<S3Client> client_;
 };
 
+// Credentials provider wrapper whose underlying provider is released by
+// FinalizeS3(), even if S3Options copies outlive it. CRT-based providers
+// (e.g. STS web identity) hold a reference to the default ClientBootstrap
+// and would otherwise make Aws::ShutdownAPI() block forever (GH-50188).
+class FinalizableCredentialsProvider : public 
Aws::Auth::AWSCredentialsProvider {
+ public:
+  explicit FinalizableCredentialsProvider(
+      std::shared_ptr<Aws::Auth::AWSCredentialsProvider> provider)
+      : provider_(std::move(provider)) {}
+
+  Aws::Auth::AWSCredentials GetAWSCredentials() override {
+    std::shared_ptr<Aws::Auth::AWSCredentialsProvider> provider;
+    {
+      std::unique_lock lock(mutex_);
+      provider = provider_;
+    }
+    if (!provider) {
+      // S3 was finalized
+      return {};
+    }
+    return provider->GetAWSCredentials();
+  }
+
+  void Finalize() {
+    std::shared_ptr<Aws::Auth::AWSCredentialsProvider> provider;
+    {
+      std::unique_lock lock(mutex_);
+      provider = std::move(provider_);

Review Comment:
   nit: maybe a comment so intent is clear.
   ```suggestion
         // Don't reset as provider's destructor could run while mutex is 
locked and could deadlock
         provider = std::move(provider_);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to