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

(cherry picked from commit e19b37ead2)
This commit is contained in:
Kihwal Lee 2016-09-28 09:46:42 -05:00
parent 3f1d3e3177
commit baf8aac05c
1 changed files with 22 additions and 3 deletions

View File

@ -109,6 +109,7 @@ import org.apache.hadoop.security.authorize.ServiceAuthorizationManager;
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;
@ -955,10 +956,16 @@ public abstract class Server {
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;
} }
@ -968,6 +975,9 @@ public abstract class Server {
} }
} 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!");
} }
} }
} }
@ -1186,9 +1196,18 @@ public abstract class Server {
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);
} }