Skip to content

Commit

Permalink
fix: don't deadlock the runtime when fetching MSK auth token (#803)
Browse files Browse the repository at this point in the history
  • Loading branch information
emef authored Dec 5, 2024
1 parent 81be75c commit 29e916f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions crates/arroyo-connectors/src/kafka/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use std::num::NonZeroU32;
use std::sync::Arc;
use std::thread;
use std::time::{Duration, Instant, SystemTime};
use tokio::runtime::Handle;
use tokio::sync::mpsc::Sender;
use tokio::sync::oneshot;
use tokio::sync::oneshot::Receiver;
Expand Down Expand Up @@ -985,16 +984,17 @@ impl ClientContext for Context {
self.config.as_ref().map(|c| &c.authentication)
{
let region = Region::new(region.clone());
let rt = Handle::current();

let (token, expiration_time_ms) = {
let handle = thread::spawn(move || {
rt.block_on(async {
let (token, expiration_time_ms) = thread::spawn(move || {
tokio::runtime::Runtime::new()?
.block_on(async {
timeout(Duration::from_secs(10), generate_auth_token(region.clone())).await
})
});
handle.join().unwrap()??
};
.map_err(|e| anyhow!("timed out generating MSK oauth token {:?}", e))?
.map_err(|e| anyhow!("signing error {:?}", e))
})
.join()
.map_err(|e| anyhow!("failed to join thread {:?}", e))??;

Ok(OAuthToken {
token,
Expand Down

0 comments on commit 29e916f

Please sign in to comment.