HADOOP-10622. Shell.runCommand can deadlock. Contributed by Gera Shegalov

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1602033 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason Darrell Lowe 2014-06-11 22:05:04 +00:00
parent 22ec67ea6f
commit 1758f3146a
2 changed files with 20 additions and 13 deletions

View File

@ -532,6 +532,8 @@ Release 2.5.0 - UNRELEASED
HADOOP-10656. The password keystore file is not picked by LDAP group mapping HADOOP-10656. The password keystore file is not picked by LDAP group mapping
(brandonli) (brandonli)
HADOOP-10622. Shell.runCommand can deadlock (Gera Shegalov via jlowe)
BREAKDOWN OF HADOOP-10514 SUBTASKS AND RELATED JIRAS BREAKDOWN OF HADOOP-10514 SUBTASKS AND RELATED JIRAS
HADOOP-10520. Extended attributes definition and FileSystem APIs for HADOOP-10520. Extended attributes definition and FileSystem APIs for

View File

@ -526,12 +526,8 @@ public void run() {
} }
// wait for the process to finish and check the exit code // wait for the process to finish and check the exit code
exitCode = process.waitFor(); exitCode = process.waitFor();
try { // make sure that the error thread exits
// make sure that the error thread exits joinThread(errThread);
errThread.join();
} catch (InterruptedException ie) {
LOG.warn("Interrupted while reading the error stream", ie);
}
completed.set(true); completed.set(true);
//the timeout thread handling //the timeout thread handling
//taken care in finally block //taken care in finally block
@ -560,13 +556,9 @@ public void run() {
} catch (IOException ioe) { } catch (IOException ioe) {
LOG.warn("Error while closing the input stream", ioe); LOG.warn("Error while closing the input stream", ioe);
} }
try { if (!completed.get()) {
if (!completed.get()) { errThread.interrupt();
errThread.interrupt(); joinThread(errThread);
errThread.join();
}
} catch (InterruptedException ie) {
LOG.warn("Interrupted while joining errThread");
} }
try { try {
InputStream stderr = process.getErrorStream(); InputStream stderr = process.getErrorStream();
@ -581,6 +573,19 @@ public void run() {
} }
} }
private static void joinThread(Thread t) {
while (t.isAlive()) {
try {
t.join();
} catch (InterruptedException ie) {
if (LOG.isWarnEnabled()) {
LOG.warn("Interrupted while joining on: " + t, ie);
}
t.interrupt(); // propagate interrupt
}
}
}
/** return an array containing the command name & its parameters */ /** return an array containing the command name & its parameters */
protected abstract String[] getExecString(); protected abstract String[] getExecString();