fix: use existing tokio Handle instead of spawning new runtime for email config
All checks were successful
BotServer CI/CD / build (push) Successful in 4m32s

This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2026-04-05 00:13:10 -03:00
parent 645a7936c5
commit eba075bb9d

View file

@ -869,15 +869,9 @@ 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(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);
@ -894,14 +888,8 @@ impl SecretsManager {
}
}
None
})
} else {
None
};
let _ = tx.send(result);
});
if let Ok(Some(secrets)) = rx.recv_timeout(std::time::Duration::from_secs(5)) {
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),
@ -910,6 +898,7 @@ impl SecretsManager {
secrets.get("smtp_from").cloned().unwrap_or_default(),
);
}
}
(String::new(), 587, String::new(), String::new(), String::new())
}