hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ecl...@apache.org
Subject svn commit: r1545895 - /hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java
Date Wed, 27 Nov 2013 00:57:13 GMT
Author: eclark
Date: Wed Nov 27 00:57:13 2013
New Revision: 1545895

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

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

Modified: hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java?rev=1545895&r1=1545894&r2=1545895&view=diff
==============================================================================
--- hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java
(original)
+++ hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java
Wed Nov 27 00:57:13 2013
@@ -743,9 +743,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 {
@@ -1368,20 +1373,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() {



Mime
View raw message