From 8a0b023023554ba0d65c72f57b242d84bfe2b132 Mon Sep 17 00:00:00 2001 From: Duo Zhang Date: Mon, 4 Jan 2021 23:30:32 +0800 Subject: [PATCH] =?UTF-8?q?HBASE-25457=20Possible=20race=20in=20AsyncConne?= =?UTF-8?q?ctionImpl=20between=20getChoreServ=E2=80=A6=20(#2839)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Viraj Jasani --- .../hadoop/hbase/client/AsyncConnectionImpl.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncConnectionImpl.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncConnectionImpl.java index 1dbb7e6d211..8a1ac5aac76 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncConnectionImpl.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncConnectionImpl.java @@ -28,8 +28,6 @@ import static org.apache.hadoop.hbase.client.NonceGenerator.CLIENT_NONCES_ENABLE import static org.apache.hadoop.hbase.util.FutureUtils.addListener; import java.io.IOException; -import java.net.InetAddress; -import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.Optional; import java.util.concurrent.CompletableFuture; @@ -56,11 +54,11 @@ import org.apache.hadoop.hbase.security.User; import org.apache.hadoop.hbase.util.ConcurrentMapUtils; import org.apache.hadoop.hbase.util.Threads; import org.apache.hadoop.security.UserGroupInformation; -import org.apache.hbase.thirdparty.com.google.common.util.concurrent.ThreadFactoryBuilder; import org.apache.yetus.audience.InterfaceAudience; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.apache.hbase.thirdparty.com.google.common.util.concurrent.ThreadFactoryBuilder; import org.apache.hbase.thirdparty.io.netty.util.HashedWheelTimer; import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService; @@ -187,6 +185,9 @@ class AsyncConnectionImpl implements AsyncConnection { * @return ChoreService */ synchronized ChoreService getChoreService() { + if (isClosed()) { + throw new IllegalStateException("connection is already closed"); + } if (choreService == null) { choreService = new ChoreService("AsyncConn Chore Service"); } @@ -216,8 +217,11 @@ class AsyncConnectionImpl implements AsyncConnection { e -> LOG.warn("failed to close clusterStatusListener", e)); IOUtils.closeQuietly(rpcClient, e -> LOG.warn("failed to close rpcClient", e)); IOUtils.closeQuietly(registry, e -> LOG.warn("failed to close registry", e)); - if (choreService != null) { - choreService.shutdown(); + synchronized (this) { + if (choreService != null) { + choreService.shutdown(); + choreService = null; + } } metrics.ifPresent(MetricsConnection::shutdown); ConnectionOverAsyncConnection c = this.conn;