From 21170faea937a80879b3f07036414279130ea380 Mon Sep 17 00:00:00 2001 From: "Rodrigo Rodriguez (Pragmatismo)" Date: Fri, 3 Apr 2026 12:05:18 -0300 Subject: [PATCH] fix: remove block_in_place wrappers that panic inside spawn_blocking 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) --- src/core/shared/utils.rs | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/core/shared/utils.rs b/src/core/shared/utils.rs index c8f27a41..da022403 100644 --- a/src/core/shared/utils.rs +++ b/src/core/shared/utils.rs @@ -54,13 +54,11 @@ pub fn get_database_url_sync() -> Result { 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()) - }); + let rt = tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + .map_err(|e| anyhow::anyhow!("Failed to create runtime: {}", e))?; + 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,17 +84,15 @@ pub fn get_secrets_manager_sync() -> Option { 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() - .ok(); - match rt { - Some(rt) => rt.block_on(sm.get_value("gbo/app", "work_path")) - .unwrap_or_else(|_| "./work".to_string()), - None => "./work".to_string(), - } - }) + let rt = tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + .ok(); + match rt { + Some(rt) => rt.block_on(sm.get_value("gbo/app", "work_path")) + .unwrap_or_else(|_| "./work".to_string()), + None => "./work".to_string(), + } } else { "./work".to_string() }