FAROS
FAROS copied to clipboard
Search service `_rate_limit` blocks async event loop with `time.sleep`
Search service _rate_limit blocks async event loop with time.sleep
Severity: High
File: backend/app/services/search_service.py:139
The _rate_limit method uses synchronous time.sleep() to enforce rate limiting for Semantic Scholar API calls. When called from async FastAPI endpoints, this blocks the entire event loop, preventing other requests from being processed during the sleep period.
def _rate_limit(self):
"""Ensure we don't exceed rate limits."""
elapsed = time.time() - self.last_request_time
if elapsed < self.min_request_interval:
time.sleep(self.min_request_interval - elapsed)
self.last_request_time = time.time()
Why it matters
Concurrent idea generation sessions or literature searches will queue up and experience degraded performance. A single slow search can block the entire backend for 3+ seconds.