From eba075bb9d89855785232f67589d08549cd06dab Mon Sep 17 00:00:00 2001 From: "Rodrigo Rodriguez (Pragmatismo)" Date: Sun, 5 Apr 2026 00:13:10 -0300 Subject: [PATCH] fix: use existing tokio Handle instead of spawning new runtime for email config --- src/core/secrets/mod.rs | 59 +++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 35 deletions(-) diff --git a/src/core/secrets/mod.rs b/src/core/secrets/mod.rs index a1865889..127f190e 100644 --- a/src/core/secrets/mod.rs +++ b/src/core/secrets/mod.rs @@ -869,46 +869,35 @@ impl SecretsManager { let bot_path = format!("gbo/bots/{}/email", bot_id); let default_path = "gbo/bots/default/email".to_string(); let self_owned = self.clone(); - let (tx, rx) = std::sync::mpsc::channel(); - std::thread::spawn(move || { - let rt = tokio::runtime::Builder::new_multi_thread() - .enable_all() - .worker_threads(1) - .build(); - let result = if let Ok(rt) = rt { - rt.block_on(async move { - if let Ok(s) = self_owned.get_secret(&bot_path).await { - if !s.is_empty() && s.contains_key("smtp_from") { - return Some(s); - } + if let Ok(handle) = tokio::runtime::Handle::try_current() { + let result = handle.block_on(async move { + if let Ok(s) = self_owned.get_secret(&bot_path).await { + if !s.is_empty() && s.contains_key("smtp_from") { + return Some(s); } - if let Ok(s) = self_owned.get_secret(&default_path).await { - if !s.is_empty() && s.contains_key("smtp_from") { - return Some(s); - } + } + if let Ok(s) = self_owned.get_secret(&default_path).await { + if !s.is_empty() && s.contains_key("smtp_from") { + return Some(s); } - if let Ok(s) = self_owned.get_secret(SecretPaths::EMAIL).await { - if !s.is_empty() && s.contains_key("smtp_from") { - return Some(s); - } + } + if let Ok(s) = self_owned.get_secret(SecretPaths::EMAIL).await { + if !s.is_empty() && s.contains_key("smtp_from") { + return Some(s); } - None - }) - } else { + } None - }; - let _ = tx.send(result); - }); - - if let Ok(Some(secrets)) = rx.recv_timeout(std::time::Duration::from_secs(5)) { - return ( - secrets.get("smtp_host").cloned().unwrap_or_default(), - secrets.get("smtp_port").and_then(|p| p.parse().ok()).unwrap_or(587), - secrets.get("smtp_user").cloned().unwrap_or_default(), - secrets.get("smtp_password").cloned().unwrap_or_default(), - secrets.get("smtp_from").cloned().unwrap_or_default(), - ); + }); + if let Some(secrets) = result { + return ( + secrets.get("smtp_host").cloned().unwrap_or_default(), + secrets.get("smtp_port").and_then(|p| p.parse().ok()).unwrap_or(587), + secrets.get("smtp_user").cloned().unwrap_or_default(), + secrets.get("smtp_password").cloned().unwrap_or_default(), + secrets.get("smtp_from").cloned().unwrap_or_default(), + ); + } } (String::new(), 587, String::new(), String::new(), String::new()) }