fix: init_redis uses async Vault call instead of sync block_on (fixes panic)
All checks were successful
BotServer CI/CD / build (push) Successful in 5m40s

- 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
This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2026-04-02 06:59:21 -03:00
parent b3edf21d21
commit f118c74cf1

View file

@ -284,6 +284,8 @@ pub async fn load_config(
/// Initialize Redis/Valkey cache with retry logic /// Initialize Redis/Valkey cache with retry logic
#[cfg(feature = "cache")] #[cfg(feature = "cache")]
pub async fn init_redis() -> Option<Arc<redis::Client>> { pub async fn init_redis() -> Option<Arc<redis::Client>> {
use crate::core::secrets::{SecretPaths, SecretsManager};
// Try environment variables first // Try environment variables first
let cache_url = std::env::var("CACHE_URL") let cache_url = std::env::var("CACHE_URL")
.or_else(|_| std::env::var("REDIS_URL")) .or_else(|_| std::env::var("REDIS_URL"))
@ -293,12 +295,18 @@ pub async fn init_redis() -> Option<Arc<redis::Client>> {
// If no env var, try to get credentials from Vault // If no env var, try to get credentials from Vault
let cache_url = if let Some(url) = cache_url { let cache_url = if let Some(url) = cache_url {
url url
} else if let Some(secrets) = crate::core::shared::utils::get_secrets_manager().await { } else if let Ok(secrets) = SecretsManager::from_env() {
let (host, port, password) = secrets.get_cache_config(); match secrets.get_secret(SecretPaths::CACHE).await {
if let Some(pass) = password { Ok(data) => {
format!("redis://:{}@{}:{}", pass, host, port) let host = data.get("host").cloned().unwrap_or_else(|| "localhost".into());
} else { let port = data.get("port").and_then(|p| p.parse().ok()).unwrap_or(6379);
format!("redis://{}:{}", host, port) if let Some(pass) = data.get("password") {
format!("redis://:{}@{}:{}", pass, host, port)
} else {
format!("redis://{}:{}", host, port)
}
}
Err(_) => "redis://localhost:6379".to_string(),
} }
} else { } else {
"redis://localhost:6379".to_string() "redis://localhost:6379".to_string()