From e364883a659993d2a69cd258b003cfeb6bb59270 Mon Sep 17 00:00:00 2001 From: sylvinho81 Date: Wed, 18 Feb 2026 09:27:53 +0100 Subject: [PATCH 1/2] Add gRPC ping check to is_live method --- integration/test_client.py | 24 +++++++++++++++++ weaviate/client_executor.py | 52 +++++++++++++++++++++++++++++++++---- 2 files changed, 71 insertions(+), 5 deletions(-) diff --git a/integration/test_client.py b/integration/test_client.py index 7742e197a..a96a43bf4 100644 --- a/integration/test_client.py +++ b/integration/test_client.py @@ -634,6 +634,30 @@ async def test_async_client_is_ready() -> None: assert await client.is_ready() +def test_client_is_not_live() -> None: + assert not weaviate.WeaviateClient( + connection_params=weaviate.connect.ConnectionParams.from_url( + "http://localhost:8080", 50051 + ), + skip_init_checks=True, + ).is_live() + + +def test_client_is_live() -> None: + with weaviate.connect_to_wcs( + cluster_url=WCS_URL, auth_credentials=WCS_CREDS, skip_init_checks=True + ) as client: + assert client.is_live() + + +@pytest.mark.asyncio +async def test_async_client_is_live() -> None: + async with weaviate.use_async_with_weaviate_cloud( + cluster_url=WCS_URL, auth_credentials=WCS_CREDS, skip_init_checks=True + ) as client: + assert await client.is_live() + + def test_local_proxies() -> None: with weaviate.connect_to_local( additional_config=wvc.init.AdditionalConfig( diff --git a/weaviate/client_executor.py b/weaviate/client_executor.py index 6d1d0c59b..cec92f80b 100644 --- a/weaviate/client_executor.py +++ b/weaviate/client_executor.py @@ -2,12 +2,14 @@ from typing import ( Any, + Awaitable, Dict, Generic, Optional, Tuple, Type, Union, + cast, ) from httpx import Response @@ -151,9 +153,14 @@ def connect(self) -> executor.Result[None]: method=self._connection.connect, ) - def is_live(self) -> executor.Result[bool]: - def resp(res: Response) -> bool: - return res.status_code == 200 + def __check_grpc_live(self) -> executor.Result[bool]: + """Check if the gRPC endpoint is live by pinging it.""" + grpc_colour: executor.Colour = ( + "async" if isinstance(self._connection, ConnectionAsync) else "sync" + ) + + def resp(_: None) -> bool: + return True def exc(e: Exception) -> bool: print(e) @@ -162,8 +169,43 @@ def exc(e: Exception) -> bool: return executor.execute( response_callback=resp, exception_callback=exc, - method=self._connection.get, - path="/.well-known/live", + method=self._connection._ping_grpc, + colour=grpc_colour, + ) + + def is_live(self) -> executor.Result[bool]: + """Check if the Weaviate instance is live by pinging both HTTP and gRPC endpoints. + + Returns: + `True` if both HTTP and gRPC endpoints are live, `False` otherwise. + """ + + def resp(res: Response) -> Union[bool, Awaitable[bool]]: + if res.status_code != 200: + return False + + # HTTP is live, now check gRPC + grpc_result = self.__check_grpc_live() + if isinstance(grpc_result, Awaitable): + + async def await_grpc_result() -> bool: + return await grpc_result + + return cast(Awaitable[bool], await_grpc_result()) + return grpc_result + + def exc(e: Exception) -> bool: + print(e) + return False + + return cast( + executor.Result[bool], + executor.execute( + response_callback=resp, + exception_callback=exc, + method=self._connection.get, + path="/.well-known/live", + ), ) def is_ready(self) -> executor.Result[bool]: From 9b8ff298ff0797c7a0b2fe3229c17be4a9d0cd41 Mon Sep 17 00:00:00 2001 From: sylvinho81 Date: Wed, 18 Feb 2026 11:57:49 +0100 Subject: [PATCH 2/2] test client is not live with wrong port --- integration/test_client.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/integration/test_client.py b/integration/test_client.py index a96a43bf4..8b6df4935 100644 --- a/integration/test_client.py +++ b/integration/test_client.py @@ -658,6 +658,23 @@ async def test_async_client_is_live() -> None: assert await client.is_live() +def test_client_is_not_live_with_wrong_rest_port() -> None: + with weaviate.connect_to_local(skip_init_checks=True) as client: + # Simulate a wrong REST port after connecting. + client._connection.url = "http://localhost:9000" + assert not client.is_live() + + +def test_client_is_not_live_with_wrong_grpc_port() -> None: + with weaviate.connect_to_local(skip_init_checks=True) as client: + # Simulate a wrong gRPC port after connecting. + client._connection._connection_params.grpc.port = 90000 + # Clear channel and stub so ping fails and cleanup doesn't break + client._connection._grpc_channel = None + client._connection._grpc_stub = None + assert not client.is_live() + + def test_local_proxies() -> None: with weaviate.connect_to_local( additional_config=wvc.init.AdditionalConfig(