[#8668] improvement(core): prevent handing out new clients after pool closure (#8682)
### What changes were proposed in this pull request?
- Fixed an issue in `ClientPoolImpl#get` where a new client could still
be returned after the pool was closed.
- Modified the loop to re-check the `closed` flag to ensure no new
clients are created or returned after pool closure.
### Why are the changes needed?
Improved so that when the pool is closed, `get()` calls fail and throw
an exception.
Fix: #8668
### Does this PR introduce _any_ user-facing change?
No user-facing changes.
### How was this patch tested?
Executed existing unit tests
---------
Co-authored-by: Mini Yu <yuqi@datastrato.com>
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 5aa0528..ae2cd99 100644
--- a/core/src/main/java/org/apache/gravitino/utils/ClientPoolImpl.java
+++ b/core/src/main/java/org/apache/gravitino/utils/ClientPoolImpl.java
@@ -18,7 +18,6 @@
*/
package org.apache.gravitino.utils;
-import com.google.common.base.Preconditions;
import java.io.Closeable;
import java.util.ArrayDeque;
import java.util.Deque;
@@ -131,8 +130,10 @@
}
private C get() throws InterruptedException {
- Preconditions.checkState(!closed, "Cannot get a client from a closed pool");
while (true) {
+ if (closed) {
+ throw new IllegalArgumentException("Cannot get a client from a closed pool");
+ }
if (!clients.isEmpty() || currentSize < poolSize) {
synchronized (this) {
if (!clients.isEmpty()) {