From 476b56cd64f5e3d6f29250acbf50df2e01d51e02 Mon Sep 17 00:00:00 2001 From: yhmo Date: Mon, 4 Nov 2024 15:52:22 +0800 Subject: [PATCH] Client throw exception if failed to get client Signed-off-by: yhmo --- src/main/java/io/milvus/pool/ClientPool.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/milvus/pool/ClientPool.java b/src/main/java/io/milvus/pool/ClientPool.java index 0c3fd2739..9d96ba787 100644 --- a/src/main/java/io/milvus/pool/ClientPool.java +++ b/src/main/java/io/milvus/pool/ClientPool.java @@ -1,5 +1,7 @@ package io.milvus.pool; +import io.milvus.v2.exception.ErrorCode; +import io.milvus.v2.exception.MilvusClientException; import org.apache.commons.pool2.impl.GenericKeyedObjectPool; import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; import org.slf4j.Logger; @@ -51,8 +53,9 @@ public T getClient(String key) { try { return clientPool.borrowObject(key); } catch (Exception e) { + // the pool might return timeout exception if it could not get a client in PoolConfig.maxBlockWaitDuration logger.error("Failed to get client, exception: ", e); - return null; + throw new MilvusClientException(ErrorCode.CLIENT_ERROR, e); } } @@ -68,8 +71,9 @@ public void returnClient(String key, T grpcClient) { try { clientPool.returnObject(key, grpcClient); } catch (Exception e) { + // the pool might return exception if the key doesn't exist or the grpcClient doesn't belong to this pool logger.error("Failed to return client, exception: " + e); - throw e; + throw new MilvusClientException(ErrorCode.CLIENT_ERROR, e); } }