From f118c74cf1a8040e5c632918f7aa72ea6feac09b Mon Sep 17 00:00:00 2001 From: "Rodrigo Rodriguez (Pragmatismo)" Date: Thu, 2 Apr 2026 06:59:21 -0300 Subject: [PATCH] fix: init_redis uses async Vault call instead of sync block_on (fixes panic) - Root cause: get_cache_config() uses runtime.block_on() which panics when called from within an async runtime - Fix: call SecretsManager::get_secret() directly with .await - Testing: compiles clean, no runtime nesting issues --- src/main_module/bootstrap.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main_module/bootstrap.rs b/src/main_module/bootstrap.rs index 35d21e15..857d1be6 100644 --- a/src/main_module/bootstrap.rs +++ b/src/main_module/bootstrap.rs @@ -284,6 +284,8 @@ pub async fn load_config( /// Initialize Redis/Valkey cache with retry logic #[cfg(feature = "cache")] pub async fn init_redis() -> Option> { + use crate::core::secrets::{SecretPaths, SecretsManager}; + // Try environment variables first let cache_url = std::env::var("CACHE_URL") .or_else(|_| std::env::var("REDIS_URL")) @@ -293,12 +295,18 @@ pub async fn init_redis() -> Option> { // If no env var, try to get credentials from Vault let cache_url = if let Some(url) = cache_url { url - } else if let Some(secrets) = crate::core::shared::utils::get_secrets_manager().await { - let (host, port, password) = secrets.get_cache_config(); - if let Some(pass) = password { - format!("redis://:{}@{}:{}", pass, host, port) - } else { - format!("redis://{}:{}", host, port) + } else if let Ok(secrets) = SecretsManager::from_env() { + match secrets.get_secret(SecretPaths::CACHE).await { + Ok(data) => { + let host = data.get("host").cloned().unwrap_or_else(|| "localhost".into()); + let port = data.get("port").and_then(|p| p.parse().ok()).unwrap_or(6379); + if let Some(pass) = data.get("password") { + format!("redis://:{}@{}:{}", pass, host, port) + } else { + format!("redis://{}:{}", host, port) + } + } + Err(_) => "redis://localhost:6379".to_string(), } } else { "redis://localhost:6379".to_string()