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
|
/// 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,13 +295,19 @@ 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) => {
|
||||||
|
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)
|
format!("redis://:{}@{}:{}", pass, host, port)
|
||||||
} else {
|
} else {
|
||||||
format!("redis://{}:{}", host, port)
|
format!("redis://{}:{}", host, port)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Err(_) => "redis://localhost:6379".to_string(),
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
"redis://localhost:6379".to_string()
|
"redis://localhost:6379".to_string()
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue