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
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:
parent
b3edf21d21
commit
f118c74cf1
1 changed files with 14 additions and 6 deletions
|
|
@ -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<Arc<redis::Client>> {
|
||||
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<Arc<redis::Client>> {
|
|||
// 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()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue