Browse Source

Client throw exception if failed to get client (#1169)

Signed-off-by: yhmo <yihua.mo@zilliz.com>
groot 6 months ago
parent
commit
24def7cf5f
1 changed files with 6 additions and 2 deletions
  1. 6 2
      src/main/java/io/milvus/pool/ClientPool.java

+ 6 - 2
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 class ClientPool<C, T> {
         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 class ClientPool<C, T> {
         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);
         }
     }