hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject hbase git commit: HBASE-14474 DeadLock in RpcClientImpl.Connection.close()
Date Fri, 25 Sep 2015 18:13:38 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1.0 7a8057b41 -> e3b260881


HBASE-14474 DeadLock in RpcClientImpl.Connection.close()


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/e3b26088
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/e3b26088
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/e3b26088

Branch: refs/heads/branch-1.0
Commit: e3b2608819f51c296b3e5108f58be1d50a9a8ed5
Parents: 7a8057b
Author: Enis Soztutar <enis@apache.org>
Authored: Fri Sep 25 11:04:53 2015 -0700
Committer: Enis Soztutar <enis@apache.org>
Committed: Fri Sep 25 11:12:16 2015 -0700

----------------------------------------------------------------------
 .../apache/hadoop/hbase/ipc/RpcClientImpl.java  | 25 +++++++++++++-------
 1 file changed, 17 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/e3b26088/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/RpcClientImpl.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/RpcClientImpl.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/RpcClientImpl.java
index a31fbcd..51b5fea 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/RpcClientImpl.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/RpcClientImpl.java
@@ -908,14 +908,20 @@ public class RpcClientImpl extends AbstractRpcClient {
           IPCUtil.write(this.out, header, call.param, cellBlock);
         } catch (IOException e) {
           // We set the value inside the synchronized block, this way the next in line
-          //  won't even try to write
-          markClosed(e);
-          close();
+          //  won't even try to write. Otherwise we might miss a call in the calls map?
+          shouldCloseConnection.set(true);
           writeException = e;
           interrupt();
         }
       }
 
+      // call close outside of the synchronized (outLock) to prevent deadlock - HBASE-14474
+      if (writeException != null) {
+        if (markClosed(writeException)) {
+          close();
+        }
+      }
+
       // We added a call, and may be started the connection close. In both cases, we
       //  need to notify the reader.
       synchronized (this) {
@@ -1016,10 +1022,11 @@ public class RpcClientImpl extends AbstractRpcClient {
           e.getStackTrace(), doNotRetry);
     }
 
-    protected synchronized void markClosed(IOException e) {
+    protected synchronized boolean markClosed(IOException e) {
       if (e == null) throw new NullPointerException();
 
-      if (shouldCloseConnection.compareAndSet(false, true)) {
+      boolean ret = shouldCloseConnection.compareAndSet(false, true);
+      if (ret) {
         if (LOG.isTraceEnabled()) {
           LOG.trace(getName() + ": marking at should close, reason: " + e.getMessage());
         }
@@ -1028,6 +1035,7 @@ public class RpcClientImpl extends AbstractRpcClient {
         }
         notifyAll();
       }
+      return ret;
     }
 
 
@@ -1136,14 +1144,15 @@ public class RpcClientImpl extends AbstractRpcClient {
     }
     if (connsToClose != null) {
       for (Connection conn : connsToClose) {
-        conn.markClosed(new InterruptedIOException("RpcClient is closing"));
-        conn.close();
+        if (conn.markClosed(new InterruptedIOException("RpcClient is closing"))) {
+          conn.close();
+        }
       }
     }
     // wait until all connections are closed
     while (!connections.isEmpty()) {
       try {
-        Thread.sleep(100);
+        Thread.sleep(10);
       } catch (InterruptedException e) {
         LOG.info("Interrupted while stopping the client. We still have " + connections.size()
+
             " connections.");


Mime
View raw message