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

Weaviate search await client.connect() not setting _connection.grpc_stub on time #1499

Open
Lucas-Aurelio-Costa opened this issue Jan 2, 2025 · 0 comments

Comments

@Lucas-Aurelio-Costa
Copy link

Lucas-Aurelio-Costa commented Jan 2, 2025

Language: Python
Version: weaviate-client 4.9.6

Context:
When trying to run a query, we check if the weaviate async client is connected.
When the client returns that it is connected, we run our queries.
However, sometimes, the client.connect() returns before it is fully connected (grpc_stub is None).

More specifically:

await client.connect()  # This is not waiting until client is fully connected (grpc_stub)

After a few second, the grpc_stub is set and the code begins to work normally, but the first calls result in an error being raised because the client._connection.grpc_stub is None.

Client initialization:

return weaviate.use_async_with_weaviate_cloud(
        cluster_url=cluster_url,
        auth_credentials=api_key,
        additional_config=weaviate.classes.init.AdditionalConfig(timeout=weaviate.classes.init.Timeout(init=10)),
        headers=None,
        skip_init_checks=True,
    )

Connecting

async def connect_to_client():
    if not client.is_connected():
        await client.connect()

Where the error happened when trying to use the client:

  File \"/usr/local/lib/python3.11/site-packages/weaviate/collections/grpc/query.py\", line 803, in __call
    assert self._connection.grpc_stub is not None
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

What we had to do to fix:

async def connect_to_client():
    if not client.is_connected() or client._connection.grpc_stub is None:
        async with lock:
            if not client.is_connected():
                await client.connect()

            while client._connection.grpc_stub is None:
                await asyncio.sleep(0.5)

So, we expect a fix on the await client.connect() to wait for the client to be fully connected

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

1 participant