You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ec...@apache.org on 2013/11/27 01:57:18 UTC

svn commit: r1545896 - /hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java

Author: eclark
Date: Wed Nov 27 00:57:17 2013
New Revision: 1545896

URL: http://svn.apache.org/r1545896
Log:
HBASE-10039 Fix potential Resource Leak in RpcServer

Modified:
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java?rev=1545896&r1=1545895&r2=1545896&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java Wed Nov 27 00:57:17 2013
@@ -754,9 +754,14 @@ public class RpcServer implements RpcSer
 
       SocketChannel channel;
       while ((channel = server.accept()) != null) {
-        channel.configureBlocking(false);
-        channel.socket().setTcpNoDelay(tcpNoDelay);
-        channel.socket().setKeepAlive(tcpKeepAlive);
+        try {
+          channel.configureBlocking(false);
+          channel.socket().setTcpNoDelay(tcpNoDelay);
+          channel.socket().setKeepAlive(tcpKeepAlive);
+        } catch (IOException ioe) {
+          channel.close();
+          throw ioe;
+        }
 
         Reader reader = getReader();
         try {
@@ -1358,20 +1363,31 @@ public class RpcServer implements RpcSer
      */
     private void doRawSaslReply(SaslStatus status, Writable rv,
         String errorClass, String error) throws IOException {
-      //In my testing, have noticed that sasl messages are usually
-      //in the ballpark of 100-200. That's why the initialcapacity is 256.
-      ByteBufferOutputStream saslResponse = new ByteBufferOutputStream(256);
-      DataOutputStream out = new DataOutputStream(saslResponse);
-      out.writeInt(status.state); // write status
-      if (status == SaslStatus.SUCCESS) {
-        rv.write(out);
-      } else {
-        WritableUtils.writeString(out, errorClass);
-        WritableUtils.writeString(out, error);
+      ByteBufferOutputStream saslResponse = null;
+      DataOutputStream out = null;
+      try {
+        // In my testing, have noticed that sasl messages are usually
+        // in the ballpark of 100-200. That's why the initial capacity is 256.
+        saslResponse = new ByteBufferOutputStream(256);
+        out = new DataOutputStream(saslResponse);
+        out.writeInt(status.state); // write status
+        if (status == SaslStatus.SUCCESS) {
+          rv.write(out);
+        } else {
+          WritableUtils.writeString(out, errorClass);
+          WritableUtils.writeString(out, error);
+        }
+        saslCall.setSaslTokenResponse(saslResponse.getByteBuffer());
+        saslCall.responder = responder;
+        saslCall.sendResponseIfReady();
+      } finally {
+        if (saslResponse != null) {
+          saslResponse.close();
+        }
+        if (out != null) {
+          out.close();
+        }
       }
-      saslCall.setSaslTokenResponse(saslResponse.getByteBuffer());
-      saslCall.responder = responder;
-      saslCall.sendResponseIfReady();
     }
 
     private void disposeSasl() {