fix: use new_current_thread runtime in get_database_url_sync to prevent nested block_on panic
All checks were successful
BotServer CI/CD / build (push) Successful in 6m30s

This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2026-04-03 09:26:23 -03:00
parent f6a864aa67
commit 263ca4ed11

View file

@ -54,7 +54,13 @@ pub fn get_database_url_sync() -> Result<String> {
let guard = SECRETS_MANAGER.read().map_err(|e| anyhow::anyhow!("Lock poisoned: {}", e))?; let guard = SECRETS_MANAGER.read().map_err(|e| anyhow::anyhow!("Lock poisoned: {}", e))?;
if let Some(ref manager) = *guard { if let Some(ref manager) = *guard {
if let Ok(handle) = tokio::runtime::Handle::try_current() { if let Ok(handle) = tokio::runtime::Handle::try_current() {
return handle.block_on(manager.get_database_url()); return tokio::task::block_in_place(|| {
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.map_err(|e| anyhow::anyhow!("Failed to create runtime: {}", e))?;
rt.block_on(manager.get_database_url())
});
} else { } else {
let rt = tokio::runtime::Runtime::new() let rt = tokio::runtime::Runtime::new()
.map_err(|e| anyhow::anyhow!("Failed to create runtime: {}", e))?; .map_err(|e| anyhow::anyhow!("Failed to create runtime: {}", e))?;