diff --git a/src/api/health.rs b/src/api/health.rs index 44980989..df9fdcea 100644 --- a/src/api/health.rs +++ b/src/api/health.rs @@ -4,7 +4,6 @@ use serde::Serialize; use std::time::Instant; use super::types::AppState; -use crate::core::cache::MongoCache; use crate::core::config; use crate::core::db::{Database, PostgresDb, RedisClient}; use crate::core::db::qdrant_db::new_http_client; @@ -181,7 +180,7 @@ struct ServiceHealth { postgres: ServiceStatus, redis: ServiceStatus, qdrant: ServiceStatus, - mongodb: ServiceStatus, + // mongodb: ServiceStatus, // Removed - now using Redis only } #[derive(Debug, Serialize)] @@ -195,12 +194,11 @@ pub async fn health(State(state): State) -> Json { let postgres = check_postgres().await; let redis = check_redis().await; let qdrant = check_qdrant().await; - let mongodb = check_mongodb(&state.mongo_cache).await; + // MongoDB removed — no longer required let all_ok = postgres.status == "ok" && redis.status == "ok" - && qdrant.status == "ok" - && mongodb.status == "ok"; + && qdrant.status == "ok"; let status = if all_ok { "ok" } else { "degraded" }; @@ -228,12 +226,11 @@ pub async fn health_detailed(State(state): State) -> Json) -> Json ServiceStatus { } } -async fn check_mongodb(cache: &MongoCache) -> ServiceStatus { - let start = Instant::now(); - match cache.health_check().await { - Ok(_) => ServiceStatus { - status: "ok".to_string(), - latency_ms: Some(start.elapsed().as_millis() as u64), - error: None, - }, - Err(e) => ServiceStatus { - status: "error".to_string(), - latency_ms: Some(start.elapsed().as_millis() as u64), - error: Some(e.to_string()), - }, - } -} - fn parse_required_migrations() -> Vec { let raw = env!("REQUIRED_MIGRATIONS"); if raw.is_empty() { @@ -631,19 +612,21 @@ async fn check_rsync() -> ServiceStatus { /// Check worker liveness via Redis health key TTL. /// Returns true if the Worker's Redis health key exists and has remaining TTL > 0. -pub async fn check_worker_alive(state: &AppState) -> bool { +pub async fn check_worker_alive(_state: &AppState) -> bool { let health_key = format!("{}health", crate::core::config::REDIS_KEY_PREFIX.as_str()); - let client = state.redis_cache.get_client().await; - let guard = client.write().await; - if let Ok(mut conn) = guard.get_conn().await { + // Use a fresh client (same pattern as check_redis) instead of the shared + // redis_cache client: the shared client's RwLock can be held indefinitely + // by a task stalled on redis reconnect, deadlocking every health check. + let client = match RedisClient::new() { + Ok(c) => c, + Err(_) => return false, + }; + if let Ok(mut conn) = client.get_conn().await { let ttl: Result = redis::cmd("TTL") .arg(&[health_key.as_str()]) .query_async(&mut conn) .await; - match ttl { - Ok(ttl) if ttl > 0 => return true, - _ => return false, - } + return matches!(ttl, Ok(ttl) if ttl > 0); } false }