Add detailed Redis connection debugging and PING test
This commit is contained in:
@@ -30,26 +30,68 @@ impl AppState {
|
||||
pub async fn new_with_config(security_config: SecurityConfig) -> Self {
|
||||
// Получаем конфигурацию для Redis с таймаутом
|
||||
let redis_url = env::var("REDIS_URL").expect("REDIS_URL must be set");
|
||||
let redis_client = RedisClient::open(redis_url).expect("Invalid Redis URL");
|
||||
|
||||
// Детальное логирование для отладки
|
||||
log::info!("🔗 Redis URL: {}", redis_url.replace(&redis_url.split('@').nth(0).unwrap_or(""), "***"));
|
||||
|
||||
// Парсим URL для детального анализа
|
||||
if let Ok(parsed_url) = url::Url::parse(&redis_url) {
|
||||
log::info!(" Host: {}", parsed_url.host_str().unwrap_or("none"));
|
||||
log::info!(" Port: {}", parsed_url.port().unwrap_or(0));
|
||||
log::info!(" Username: '{}'", parsed_url.username());
|
||||
log::info!(" Password: {}", if parsed_url.password().is_some() { "***" } else { "none" });
|
||||
}
|
||||
|
||||
let redis_client = match RedisClient::open(redis_url) {
|
||||
Ok(client) => {
|
||||
log::info!("✅ Redis client created successfully");
|
||||
client
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("❌ Failed to create Redis client: {}", e);
|
||||
panic!("Redis client creation failed: {}", e);
|
||||
}
|
||||
};
|
||||
|
||||
// Устанавливаем таймаут для Redis операций с graceful fallback
|
||||
log::info!("🔄 Attempting Redis connection with timeout: {}s", security_config.request_timeout_seconds);
|
||||
|
||||
let redis_connection = match tokio::time::timeout(
|
||||
Duration::from_secs(security_config.request_timeout_seconds),
|
||||
redis_client.get_multiplexed_async_connection(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(Ok(conn)) => {
|
||||
Ok(Ok(mut conn)) => {
|
||||
log::info!("✅ Redis connection established");
|
||||
Some(conn)
|
||||
|
||||
// Тестируем подключение простой командой
|
||||
match tokio::time::timeout(
|
||||
Duration::from_secs(2),
|
||||
conn.ping::<String>()
|
||||
).await {
|
||||
Ok(Ok(result)) => {
|
||||
log::info!("✅ Redis PING successful: {}", result);
|
||||
Some(conn)
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
log::warn!("⚠️ Redis PING failed: {}", e);
|
||||
None
|
||||
}
|
||||
Err(_) => {
|
||||
log::warn!("⚠️ Redis PING timeout");
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
log::warn!("⚠️ Redis connection failed: {}", e);
|
||||
log::warn!(" Error type: {:?}", e.kind());
|
||||
log::warn!("⚠️ Running in fallback mode without Redis (quotas disabled)");
|
||||
None
|
||||
}
|
||||
Err(_) => {
|
||||
log::warn!("⚠️ Redis connection timeout");
|
||||
log::warn!("⚠️ Redis connection timeout after {} seconds", security_config.request_timeout_seconds);
|
||||
log::warn!("⚠️ Running in fallback mode without Redis (quotas disabled)");
|
||||
None
|
||||
}
|
||||
|
||||
@@ -53,10 +53,7 @@ async fn main() -> std::io::Result<()> {
|
||||
.allowed_origin("https://discours.io")
|
||||
.allowed_origin("https://new.discours.io")
|
||||
.allowed_origin("https://testing.discours.io")
|
||||
.allowed_origin("https://testing3.discours.io")
|
||||
.allowed_origin("https://vercel.app") // для Vercel edge functions
|
||||
.allowed_origin("https://*.vercel.app") // для Vercel preview deployments
|
||||
.allowed_origin("http://localhost:3000") // для разработки
|
||||
.allowed_origin("http://localhost:3000") // FIXME: для разработки
|
||||
.allowed_methods(vec!["GET", "POST", "OPTIONS"])
|
||||
.allowed_headers(vec![
|
||||
header::CONTENT_TYPE,
|
||||
|
||||
Reference in New Issue
Block a user