World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#8483] improvement(core): prevent leaking unusable connections in ClientPoolImpl run method (#8547)
keepConcentrationf70a23522704
diff --git a/core/src/main/java/org/apache/gravitino/utils/ClientPoolImpl.java b/core/src/main/java/org/apache/gravitino/utils/ClientPoolImpl.javaindex 1ba2002946..5aa0528ee3 100644--- a/core/src/main/java/org/apache/gravitino/utils/ClientPoolImpl.java+++ b/core/src/main/java/org/apache/gravitino/utils/ClientPoolImpl.java@@ -55,6 +55,7 @@ public abstract class ClientPoolImpl<C, E extends Exception>@Overridepublic <R> R run(Action<R, C, E> action, boolean retry) throws E, InterruptedException {C client = get();+ boolean shouldRelease = true;try {return action.run(client);@@ -62,7 +63,13 @@ public abstract class ClientPoolImpl<C, E extends Exception>if (retry && isConnectionException(exc)) {try {client = reconnect(client);- } catch (Exception ignored) {+ } catch (Exception reconnectException) {+ shouldRelease = false;+ synchronized (this) {+ close(client);+ currentSize -= 1;+ }+// if reconnection throws any exception, rethrow the original failurethrow reconnectExc.cast(exc);}@@ -73,7 +80,9 @@ public abstract class ClientPoolImpl<C, E extends Exception>throw exc;} finally {- release(client);+ if (shouldRelease) {+ release(client);+ }}}