HADOOP-11780. Prevent IPC reader thread death. Contributed by Daryn Sharp.

This commit is contained in:
Kihwal Lee 2016-09-28 08:24:21 -05:00
parent 9b0fd01d2e
commit e19b37ead2

View File

@ -110,6 +110,7 @@
import org.apache.hadoop.security.token.SecretManager; import org.apache.hadoop.security.token.SecretManager;
import org.apache.hadoop.security.token.SecretManager.InvalidToken; import org.apache.hadoop.security.token.SecretManager.InvalidToken;
import org.apache.hadoop.security.token.TokenIdentifier; import org.apache.hadoop.security.token.TokenIdentifier;
import org.apache.hadoop.util.ExitUtil;
import org.apache.hadoop.util.ProtoUtil; import org.apache.hadoop.util.ProtoUtil;
import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.StringUtils;
import org.apache.hadoop.util.Time; import org.apache.hadoop.util.Time;
@ -956,10 +957,16 @@ private synchronized void doRunLoop() {
while (iter.hasNext()) { while (iter.hasNext()) {
key = iter.next(); key = iter.next();
iter.remove(); iter.remove();
if (key.isValid()) { try {
if (key.isReadable()) { if (key.isReadable()) {
doRead(key); doRead(key);
} }
} catch (CancelledKeyException cke) {
// something else closed the connection, ex. responder or
// the listener doing an idle scan. ignore it and let them
// clean up.
LOG.info(Thread.currentThread().getName() +
": connection aborted from " + key.attachment());
} }
key = null; key = null;
} }
@ -969,6 +976,9 @@ private synchronized void doRunLoop() {
} }
} catch (IOException ex) { } catch (IOException ex) {
LOG.error("Error in Reader", ex); LOG.error("Error in Reader", ex);
} catch (Throwable re) {
LOG.fatal("Bug in read selector!", re);
ExitUtil.terminate(1, "Bug in read selector!");
} }
} }
} }
@ -1187,8 +1197,17 @@ private void doRunLoop() {
SelectionKey key = iter.next(); SelectionKey key = iter.next();
iter.remove(); iter.remove();
try { try {
if (key.isValid() && key.isWritable()) { if (key.isWritable()) {
doAsyncWrite(key); doAsyncWrite(key);
}
} catch (CancelledKeyException cke) {
// something else closed the connection, ex. reader or the
// listener doing an idle scan. ignore it and let them clean
// up
RpcCall call = (RpcCall)key.attachment();
if (call != null) {
LOG.info(Thread.currentThread().getName() +
": connection aborted from " + call.connection);
} }
} catch (IOException e) { } catch (IOException e) {
LOG.info(Thread.currentThread().getName() + ": doAsyncWrite threw exception " + e); LOG.info(Thread.currentThread().getName() + ": doAsyncWrite threw exception " + e);