mr-brobot commented on code in PR #4161:
URL: https://github.com/apache/arrow-rs/pull/4161#discussion_r1182798910


##########
object_store/src/aws/mod.rs:
##########
@@ -1094,12 +1103,30 @@ impl AmazonS3Builder {
     }
 }
 
+#[cfg(feature = "aws_profile")]
+fn profile_region(profile: String) -> Option<String> {
+    use crate::aws::credential::RegionProvider;
+    use futures::executor::block_on;
+
+    let provider = profile::ProfileProvider::new(profile, None);
+
+    block_on(provider.get_region())

Review Comment:
   Good call. Unfortunately, using tokio, calling `block_on` on the current 
runtime results in the following error:
   
   `ERROR: Cannot start a runtime from within a runtime. This happens because a 
function (like block_on) attempted to block the current thread while the thread 
is being used to drive asynchronous tasks.`
   
   According to the [`tokio::Handle::block_on` 
docs](https://docs.rs/tokio/latest/tokio/runtime/struct.Handle.html#method.block_on),
 we need to spawn a new thread and block there.
   
   ```rust
   use std::{panic, thread};
   use tokio::runtime::Handle;
   
   let handle = Handle::current();
   let provider = profile::ProfileProvider::new(profile, None);
   
   let result = thread::spawn(move || handle.block_on(provider.get_region()));
   
   match result.join() {
       Ok(region) => region,
       Err(e) => panic::resume_unwind(e),
   }
   ```



-- 
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