fix: remove block_in_place wrappers that panic inside spawn_blocking
Some checks are pending
BotServer CI/CD / build (push) Waiting to run

Root cause: block_in_place + new_current_thread().block_on() panics when
called from within tokio::task::spawn_blocking because block_in_place is
designed for async worker threads, not blocking threads.

Fix: Remove all block_in_place wrappers and use new_current_thread().build().block_on()
directly. This works from both async contexts and spawn_blocking contexts.

Affected: utils.rs (get_database_url_sync, get_work_path)
This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2026-04-03 12:05:18 -03:00
parent c2982f2a33
commit 21170faea9

View file

@ -54,13 +54,11 @@ pub fn get_database_url_sync() -> Result<String> {
let guard = SECRETS_MANAGER.read().map_err(|e| anyhow::anyhow!("Lock poisoned: {}", e))?;
if let Some(ref manager) = *guard {
if tokio::runtime::Handle::try_current().is_ok() {
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())
});
return rt.block_on(manager.get_database_url());
} else {
let rt = tokio::runtime::Runtime::new()
.map_err(|e| anyhow::anyhow!("Failed to create runtime: {}", e))?;
@ -86,7 +84,6 @@ pub fn get_secrets_manager_sync() -> Option<SecretsManager> {
pub fn get_work_path() -> String {
let sm = get_secrets_manager_sync();
if let Some(sm) = sm {
tokio::task::block_in_place(|| {
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
@ -96,7 +93,6 @@ pub fn get_work_path() -> String {
.unwrap_or_else(|_| "./work".to_string()),
None => "./work".to_string(),
}
})
} else {
"./work".to_string()
}