Skip to content

Search service _rate_limit blocks async event loop with time.sleep #158

Description

@kingmathes

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions