Skip to content

bug(server): PyMilvus synchronous RPC commands freeze the ASGI event loop #82

Closed as not planned

Description

@GunaPalanivel

Problem

In both server/app.py and server-https/app.py, the milvus_search() function executes PyMilvus gRPC calls (connections.connect(), collection.load(), collection.search()). Because these are synchronous, I/O-bound methods and they are called directly within an async def context without being wrapped in asyncio.to_thread or a thread pool, they block the entire ASGI event loop.

This causes the entire server to freeze under concurrent connections.

  • Note: This is distinct from Issue Implement connection pooling for Milvus #28 (connection pooling), which addresses how many connections are opened. This issue addresses what thread those connections run on to prevent event loop starvation.

Proposed Solution

Refactor milvus_search() to wrap the PyMilvus executions in await asyncio.to_thread(<blocking_call>, *args).

Related

Activity

  1. GunaPalanivel commented on Feb 28, 2026

    @GunaPalanivel
    Author

    I'll be working on this — tracking issue filed as part of my #72 pre-work. PR incoming.

  2. ibrahimalee commented on Mar 31, 2026

    @ibrahimalee

    Hi, I'm a GSoC 2026 applicant reviewing the docs-agent codebase for my proposal on Project 1 (Agentic RAG).
    I noticed this issue while going through the server code. The core problem is that pymilvus uses gRPC under the hood, and gRPC calls are blocking by default. When collection.search() is called from within an async route handler, it blocks the entire asyncio event loop, no other requests can be served until that call completes.
    The fix is to wrap the synchronous pymilvus calls in asyncio.to_thread() (Python 3.9+), offloading the blocking I/O to a thread pool:

    results = await asyncio.to_thread(collection.search, ...)

    If Issue #28's connection pooling fix is also applied, initializing the collection object once at startup, then asyncio.to_thread wraps the search call without paying a fresh TCP handshake penalty each time.
    This matters especially for the agentic architecture planned for GSoC. An agent making 5-10 tool calls in a single user turn would fully serialize under the current implementation. Combining these two fixes would significantly reduce per-query latency.
    Happy to submit a PR for this if the asyncio.to_thread approach looks good to maintainers. Is there a reason to prefer a different executor pattern here?

  3. chasecadet commented on Nov 20, 2026

    @chasecadet
    Contributor

    Thank you for reporting this!

    We are closing pre-restructure issues targeting the legacy server/, server-https/, manifests/, kagent-feast-mcp/, or in-process SentenceTransformer prototype code. In #207, #210, #233, #240, and #249, kubeflow/docs-agent migrated to dedicated TEI (text-embeddings-inference), FastMCP (docs-agent-mcp/mcp-server/), shared modular KFP pipelines (docs-agent-mcp/pipelines/), and Helm charts (docs-agent-mcp/charts/).

    If you still observe an equivalent issue on the current main stack, please feel free to open a new issue using the current issue templates.

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