weaviate-python-client icon indicating copy to clipboard operation
weaviate-python-client copied to clipboard

Failure to connect to local instance without internet

Open bilguunchinzorigEPFL opened this issue 9 months ago • 0 comments

How to reproduce this bug?

I setup weaviate instance using docker image and run it on port 7083 and 7051. When I try to connect to my local instance using async method it returns connecttimeout exception when the internet is off, while default sync method runs completely fine. Here is the code to replicate

for i in range(10):
    print(i)
    client = weaviate.connect_to_local(
        "localhost", 7083, 7051
    )
    client.connect() <- Works completely fine. However I notice slight increased delay when internet speed is slow than offline environment.
    client.close()

for i in range(10):
    print(i)
    client = weaviate.use_async_with_local(
        "localhost", 7083, 7051
    )
    await client.connect() <- Raises ConnectTimeout
    await client.close()

Python library version: 4.16.5 /python /

Root cause

So after some digging, I found that this version checking code is not properly handled on async case.

def _check_package_version(self, colour: executor.Colour) -> executor.Result[None]:
        def resp(res: Response) -> None:
            pkg_info: dict = res.json().get("info", {})
            latest_version = pkg_info.get("version", "unknown version")
            if is_weaviate_client_too_old(client_version, latest_version):
                _Warnings.weaviate_client_too_old_vs_latest(client_version, latest_version)

        try:
            if colour == "async":

                async def _execute() -> None:
                    async with AsyncClient() as client:    # TODO: Add try except here
                        res = await client.get(PYPI_PACKAGE_URL, timeout=self.timeout_config.init)
                    return resp(res)

                return _execute()
            with Client() as client:
                res = client.get(PYPI_PACKAGE_URL, timeout=self.timeout_config.init)
            return resp(res)
        except RequestError:
            pass  # ignore any errors related to requests, it is a best-effort warning

bilguunchinzorigEPFL avatar Aug 05 '25 05:08 bilguunchinzorigEPFL