HBASE-10039 Fix potential Resource Leak in RpcServer

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1545896 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
eclark 2013-11-27 00:57:17 +00:00
parent 9eb5a28520
commit 69daad5a47
1 changed files with 32 additions and 16 deletions

View File

@ -754,9 +754,14 @@ public class RpcServer implements RpcServerInterface {
SocketChannel channel; SocketChannel channel;
while ((channel = server.accept()) != null) { while ((channel = server.accept()) != null) {
channel.configureBlocking(false); try {
channel.socket().setTcpNoDelay(tcpNoDelay); channel.configureBlocking(false);
channel.socket().setKeepAlive(tcpKeepAlive); channel.socket().setTcpNoDelay(tcpNoDelay);
channel.socket().setKeepAlive(tcpKeepAlive);
} catch (IOException ioe) {
channel.close();
throw ioe;
}
Reader reader = getReader(); Reader reader = getReader();
try { try {
@ -1358,20 +1363,31 @@ public class RpcServer implements RpcServerInterface {
*/ */
private void doRawSaslReply(SaslStatus status, Writable rv, private void doRawSaslReply(SaslStatus status, Writable rv,
String errorClass, String error) throws IOException { String errorClass, String error) throws IOException {
//In my testing, have noticed that sasl messages are usually ByteBufferOutputStream saslResponse = null;
//in the ballpark of 100-200. That's why the initialcapacity is 256. DataOutputStream out = null;
ByteBufferOutputStream saslResponse = new ByteBufferOutputStream(256); try {
DataOutputStream out = new DataOutputStream(saslResponse); // In my testing, have noticed that sasl messages are usually
out.writeInt(status.state); // write status // in the ballpark of 100-200. That's why the initial capacity is 256.
if (status == SaslStatus.SUCCESS) { saslResponse = new ByteBufferOutputStream(256);
rv.write(out); out = new DataOutputStream(saslResponse);
} else { out.writeInt(status.state); // write status
WritableUtils.writeString(out, errorClass); if (status == SaslStatus.SUCCESS) {
WritableUtils.writeString(out, error); 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() { private void disposeSasl() {