Skip to content

Commit 9d19484

Browse files
authored
fix: avoid nested tokio runtime panic in AWS credential vendor (#6689)
## Summary - `aws_config::load()` may internally create a nested tokio runtime for credential resolution (e.g. IMDS, SSO), which panics with "Cannot drop a runtime in a context where blocking is not allowed" when called inside an existing async context - Wrap the `aws_config` loading in `spawn_blocking` to isolate the internal runtime from the caller's async context
1 parent 4853487 commit 9d19484

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

  • rust/lance-namespace-impls/src/credentials

rust/lance-namespace-impls/src/credentials/aws.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,24 @@ pub struct AwsCredentialVendor {
144144
impl AwsCredentialVendor {
145145
/// Create a new AWS credential vendor with the specified configuration.
146146
pub async fn new(config: AwsCredentialVendorConfig) -> Result<Self> {
147-
let mut aws_config_loader = aws_config::defaults(BehaviorVersion::latest());
148-
149-
if let Some(ref region) = config.region {
150-
aws_config_loader = aws_config_loader.region(aws_config::Region::new(region.clone()));
151-
}
152-
153-
let aws_config = aws_config_loader.load().await;
154-
let sts_client = StsClient::new(&aws_config);
147+
// Load AWS config in a spawn_blocking context to avoid "Cannot drop a runtime"
148+
// panic. aws_config::load() may internally create a nested tokio runtime for
149+
// credential resolution (e.g., IMDS, SSO), which panics if dropped inside
150+
// an existing async context.
151+
let region = config.region.clone();
152+
let sts_client = tokio::task::spawn_blocking(move || {
153+
let rt = tokio::runtime::Handle::current();
154+
rt.block_on(async {
155+
let mut aws_config_loader = aws_config::defaults(BehaviorVersion::latest());
156+
if let Some(region) = region {
157+
aws_config_loader = aws_config_loader.region(aws_config::Region::new(region));
158+
}
159+
let aws_config = aws_config_loader.load().await;
160+
StsClient::new(&aws_config)
161+
})
162+
})
163+
.await
164+
.map_err(|e| lance_core::Error::io(format!("Failed to initialize AWS config: {:?}", e)))?;
155165

156166
Ok(Self { config, sts_client })
157167
}

0 commit comments

Comments
 (0)