This is an automated email from the ASF dual-hosted git repository.
yuqi4733 pushed a commit to branch branch-1.0
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/branch-1.0 by this push:
new 6c5536d51a [#8483] improvement(core): prevent leaking unusable
connections in ClientPoolImpl run method (#8588)
6c5536d51a is described below
commit 6c5536d51aac4420137d822c591689877c88b242
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Wed Sep 17 21:02:26 2025 +0800
[#8483] improvement(core): prevent leaking unusable connections in
ClientPoolImpl run method (#8588)
### What changes were proposed in this pull request?
This PR updates the `ClientPoolImpl#run` method to ensure unusable
connections are not leaked when a reconnection attempt fails.
### Why are the changes needed?
Previously, if a reconnection attempt failed inside `run`, the old
(unusable) client could still be released back into the pool, leading to
potential connection leaks and invalid state.
Fix: #8483
### Does this PR introduce _any_ user-facing change?
No user-facing changes.
### How was this patch tested?
Executed existing unit tests
Co-authored-by: keepConcentration <[email protected]>
---
.../java/org/apache/gravitino/utils/ClientPoolImpl.java | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/core/src/main/java/org/apache/gravitino/utils/ClientPoolImpl.java
b/core/src/main/java/org/apache/gravitino/utils/ClientPoolImpl.java
index 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>
@Override
public <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 failure
throw reconnectExc.cast(exc);
}
@@ -73,7 +80,9 @@ public abstract class ClientPoolImpl<C, E extends Exception>
throw exc;
} finally {
- release(client);
+ if (shouldRelease) {
+ release(client);
+ }
}
}