Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling get_collection fails with qdrant_client.http.exceptions.ResponseHandlingException: Event loop is closed #863

Open
BezBartek opened this issue Dec 5, 2024 · 2 comments

Comments

@BezBartek
Copy link

BezBartek commented Dec 5, 2024

Hello,

await client.get_collection("collection_name")

Fails with:

Traceback (most recent call last):
  File "/usr/local/lib/python3.13/site-packages/qdrant_client/http/api_client.py", line 178, in send_inner
    response = await self._async_client.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/httpx/_client.py", line 1674, in send
    response = await self._send_handling_auth(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<4 lines>...
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/httpx/_client.py", line 1702, in _send_handling_auth
    response = await self._send_handling_redirects(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<3 lines>...
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/httpx/_client.py", line 1739, in _send_handling_redirects
    response = await self._send_single_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/httpx/_client.py", line 1776, in _send_single_request
    response = await transport.handle_async_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/httpx/_transports/default.py", line 377, in handle_async_request
    resp = await self._pool.handle_async_request(req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/httpcore/_async/connection_pool.py", line 256, in handle_async_request
    raise exc from None
  File "/usr/local/lib/python3.13/site-packages/httpcore/_async/connection_pool.py", line 229, in handle_async_request
    await self._close_connections(closing)
  File "/usr/local/lib/python3.13/site-packages/httpcore/_async/connection_pool.py", line 345, in _close_connections
    await connection.aclose()
  File "/usr/local/lib/python3.13/site-packages/httpcore/_async/connection.py", line 173, in aclose
    await self._connection.aclose()
  File "/usr/local/lib/python3.13/site-packages/httpcore/_async/http11.py", line 258, in aclose
    await self._network_stream.aclose()
  File "/usr/local/lib/python3.13/site-packages/httpcore/_backends/anyio.py", line 53, in aclose
    await self._stream.aclose()
  File "/usr/local/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 1287, in aclose
    self._transport.close()
    ~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.13/asyncio/selector_events.py", line 1202, in close
    super().close()
    ~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.13/asyncio/selector_events.py", line 865, in close
    self._loop.call_soon(self._call_connection_lost, None)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/asyncio/base_events.py", line 829, in call_soon
    self._check_closed()
    ~~~~~~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.13/asyncio/base_events.py", line 552, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<python-input-7>", line 1, in <module>
    asyncio.run(knowledgebase.client.get_collection("knowledgebase_v1"))
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ~~~~~~~~~~^^^^^^
  File "/usr/local/lib/python3.13/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/usr/local/lib/python3.13/asyncio/base_events.py", line 721, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.13/site-packages/qdrant_client/async_qdrant_client.py", line 1999, in get_collection
    return await self._client.get_collection(collection_name=collection_name, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/qdrant_client/async_qdrant_remote.py", line 2267, in get_collection
    await self.http.collections_api.get_collection(collection_name=collection_name)
  File "/usr/local/lib/python3.13/site-packages/qdrant_client/http/api/collections_api.py", line 945, in get_collection
    return await self._build_for_get_collection(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        collection_name=collection_name,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/qdrant_client/http/api_client.py", line 151, in request
    return await self.send(request, type_)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/qdrant_client/http/api_client.py", line 168, in send
    response = await self.middleware(request, self.send_inner)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/qdrant_client/http/api_client.py", line 200, in __call__
    return await call_next(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/qdrant_client/http/api_client.py", line 180, in send_inner
    raise ResponseHandlingException(e)
qdrant_client.http.exceptions.ResponseHandlingException: Event loop is closed

Other methods, that I am using, like search, collection_exists, etc. works.

It fails even in fresh terminal sessions wrapped into asyncio.run.

It fails only on production! on my local PC with same config that comand works.
There is no difference in setup.

Thanks for help

Also:
this code from AsyncQdrantFastembedMixin add method.:
image
hides real issue,
I found that get_collection fails by digging into sentry log:
image
that happen because qdrant client tries to create collection no matter what, and hides exception from rise.

@joein
Copy link
Member

joein commented Dec 16, 2024

Hey @BezBartek
Sorry for the waiting time
Could you provide a code snippet, so we could try to debug it?
Also, could you provide information about qdrant-client version you're using, OS and python version?

@BezBartek
Copy link
Author

@joein
Hello
"qdrant-client[fastembed]==1.12.1",
Env is python docker compose for python 3.13: FROM python:3.13.0

class Database:
   def __init__(self, url, api_key):
       self.collection_name = "database_v1"
       self.client = AsyncQdrantClient(
           url=url,
           api_key=api_key,
       )
       self.client.set_model(
           "mixedbread-ai/mxbai-embed-large-v1", 
       )
       self.client.set_sparse_model("prithivida/Splade_PP_en_v1")

   async def set_up_collection(self):
       if not await self.client.collection_exists(self.collection_name):
           logger.info(f"Collection {self.collection_name} does not exists.")
           await self.client.create_collection(
               collection_name=self.collection_name,
               vectors_config=self.client.get_fastembed_vector_params(),
               sparse_vectors_config=self.client.get_fastembed_sparse_vector_params(),
           )
       else:
           logger.info(f"Collection {self.collection_name} already exists.")

   async def add(self, message: str, metadata: MessageMetaData):
       await self.client.add(
           collection_name=self.collection_name, documents=[message], metadata=[metadata]
       )

   async def search(self, query_text: str, limit: int = 10, query_filter=None):
       response = await self.client.query(
           collection_name=self.collection_name,
           query_text=query_text,
           query_filter=query_filter,
           limit=limit,
       )
       return response

I init that class globally, and I am using it at slack_bolt app event hooks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants