From dc1f8fcfb27efb5ebf4e33358bd2c0a8ef2aebe1 Mon Sep 17 00:00:00 2001 From: furkanyigit34 <134547018+furkanyigit34@users.noreply.github.com> Date: Fri, 27 Mar 2026 17:01:14 +0300 Subject: [PATCH] fix: SSE timeout during social proof collection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ne yaptık: - time.sleep() → await asyncio.sleep() ile event loop bloklanması engellendi - Sosyal kanıt batch size 5 → 20 (1115 istek → 279 istek, %75 azalma) - SSE keepalive heartbeat eklendi (her 10 batch'te bir) - Nginx proxy timeout 180s → 600s (10 dakika) - Rate limit sleep süreleri optimize edildi (2s→1.5s, 0.5s→0.3s) Neden yaptık: - Kadın kategorisi gibi büyük raporlarda (82 yaprak kategori, 5576 ürün) sosyal kanıt aşamasında SSE bağlantısı kopuyordu. Kök neden: senkron time.sleep() async generator içinde event loop'u blokluyor, proxy idle timeout'a takılıyor ve bağlantıyı kesiyordu. Co-Authored-By: Claude Opus 4.6 (1M context) --- admin-panel/nginx.conf | 4 ++-- backend/main.py | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/admin-panel/nginx.conf b/admin-panel/nginx.conf index f557a74..8c9a4d7 100644 --- a/admin-panel/nginx.conf +++ b/admin-panel/nginx.conf @@ -37,8 +37,8 @@ server { # Timeouts for long-running operations proxy_connect_timeout 60s; - proxy_send_timeout 180s; - proxy_read_timeout 180s; + proxy_send_timeout 600s; + proxy_read_timeout 600s; # Disable buffering for streaming responses proxy_buffering off; diff --git a/backend/main.py b/backend/main.py index 563ba3c..6ba925c 100644 --- a/backend/main.py +++ b/backend/main.py @@ -1567,8 +1567,8 @@ async def create_report( yield f"data: {json_module.dumps({'type': 'error', 'message': f'❌ {cat_name} - Hata: {str(e)}', 'progress': progress})}\n\n" await asyncio.sleep(0.1) - # Rate limiting - time.sleep(2.0) + # Rate limiting (non-blocking) + await asyncio.sleep(1.5) # ============================================ # Sosyal Kanıt Verilerini Topla @@ -1630,7 +1630,7 @@ async def create_report( social_proof_data = {} total_products = len(all_product_ids) processed = 0 - batch_size = 5 + batch_size = 20 # print(f"🔍 DEBUG: Toplam {total_products} ürün ID'si toplandı") # print(f"🔍 DEBUG: İlk 5 ürün ID'si: {all_product_ids[:5] if all_product_ids else 'YOK'}") @@ -1677,8 +1677,10 @@ async def create_report( processed += len(chunk) progress_pct = int((processed / total_products) * 5) + 85 # 85-90% yield f"data: {json_module.dumps({'type': 'info', 'message': f'📊 Sosyal kanıt: {processed}/{total_products} ürün', 'progress': progress_pct})}\n\n" - await asyncio.sleep(0.02) - time.sleep(0.5) # Rate limiting + # SSE keepalive heartbeat every 10 batches + if processed % (batch_size * 10) == 0: + yield f": heartbeat\n\n" + await asyncio.sleep(0.3) # Rate limiting (non-blocking) # print(f"✅ DEBUG: Sosyal kanıt toplama tamamlandı. Toplanan veri: {len(social_proof_data)} ürün") yield f"data: {json_module.dumps({'type': 'success', 'message': f'✅ Sosyal kanıt verileri toplandı ({len(social_proof_data)} ürün)', 'progress': 90})}\n\n"