From 8b02374c8d23130e6fc85f032fd89fd1e0886f02 Mon Sep 17 00:00:00 2001 From: XuanYang-cn Date: Fri, 1 Mar 2024 11:38:51 +0800 Subject: [PATCH] enhance: change connection timeout to clearer msg (#1915) Signed-off-by: yangxuan --- pymilvus/client/check.py | 5 +---- pymilvus/client/grpc_handler.py | 2 +- pymilvus/orm/connections.py | 14 ++++++++++---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/pymilvus/client/check.py b/pymilvus/client/check.py index a567c7459..b979926f7 100644 --- a/pymilvus/client/check.py +++ b/pymilvus/client/check.py @@ -23,10 +23,7 @@ def is_legal_address(addr: Any) -> bool: def is_legal_host(host: Any) -> bool: - if not isinstance(host, str): - return False - - if len(host) == 0: + if not isinstance(host, str) or len(host) == 0 or (":" in host): return False return True diff --git a/pymilvus/client/grpc_handler.py b/pymilvus/client/grpc_handler.py index de472d867..adad13474 100644 --- a/pymilvus/client/grpc_handler.py +++ b/pymilvus/client/grpc_handler.py @@ -145,7 +145,7 @@ def _wait_for_channel_ready(self, timeout: Union[float] = 10): except grpc.FutureTimeoutError as e: raise MilvusException( code=Status.CONNECT_FAILED, - message=f"Fail connecting to server on {self._address}. Timeout", + message=f"Fail connecting to server on {self._address}, illegal connection params or server unavailable", ) from e except Exception as e: raise e from e diff --git a/pymilvus/orm/connections.py b/pymilvus/orm/connections.py index 88764f081..1373f93c2 100644 --- a/pymilvus/orm/connections.py +++ b/pymilvus/orm/connections.py @@ -257,11 +257,17 @@ def __get_full_address( address, parsed = self.__parse_address_from_uri(uri) return address, parsed - host = host if host != "" else Config.DEFAULT_HOST - port = port if port != "" else Config.DEFAULT_PORT - self.__verify_host_port(host, port) + _host = host if host != "" else Config.DEFAULT_HOST + _port = port if port != "" else Config.DEFAULT_PORT + self.__verify_host_port(_host, _port) + + addr = f"{_host}:{_port}" + if not is_legal_address(addr): + raise ConnectionConfigException( + message=f"Illegal host: {host} or port: {port}, should be in form of '111.1.1.1', '19530'" + ) - return f"{host}:{port}", None + return addr, None def disconnect(self, alias: str): """Disconnects connection from the registry.