diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java index 78f77c2..6818260 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java @@ -925,7 +925,7 @@ private void runCommand() throws IOException { final BufferedReader errReader = new BufferedReader(new InputStreamReader( process.getErrorStream(), Charset.defaultCharset())); - BufferedReader inReader = + final BufferedReader inReader = new BufferedReader(new InputStreamReader( process.getInputStream(), Charset.defaultCharset())); final StringBuffer errMsg = new StringBuffer(); @@ -947,8 +947,26 @@ public void run() { } } }; + + Thread inThread = new Thread() { + @Override + public void run() { + try { + parseExecResult(inReader); // parse the output + // clear the input stream buffer + String line = inReader.readLine(); + while(line != null) { + line = inReader.readLine(); + } + } catch(IOException ioe) { + LOG.warn("Error reading the input stream", ioe); + } + } + }; + try { errThread.start(); + inThread.start(); } catch (IllegalStateException ise) { } catch (OutOfMemoryError oe) { LOG.error("Caught " + oe + ". One possible reason is that ulimit" @@ -957,16 +975,11 @@ public void run() { throw oe; } try { - parseExecResult(inReader); // parse the output - // clear the input stream buffer - String line = inReader.readLine(); - while(line != null) { - line = inReader.readLine(); - } // wait for the process to finish and check the exit code exitCode = process.waitFor(); // make sure that the error thread exits joinThread(errThread); + joinThread(inThread); completed.set(true); //the timeout thread handling //taken care in finally block @@ -981,6 +994,14 @@ public void run() { if (timeOutTimer != null) { timeOutTimer.cancel(); } + if (!completed.get()) { + process.destroy(); + inThread.interrupt(); + errThread.interrupt(); + joinThread(inThread); + joinThread(errThread); + } + // close the input stream try { // JDK 7 tries to automatically drain the input streams for us @@ -997,10 +1018,6 @@ public void run() { } catch (IOException ioe) { LOG.warn("Error while closing the input stream", ioe); } - if (!completed.get()) { - errThread.interrupt(); - joinThread(errThread); - } try { InputStream stderr = process.getErrorStream(); synchronized (stderr) { @@ -1009,7 +1026,6 @@ public void run() { } catch (IOException ioe) { LOG.warn("Error while closing the error stream", ioe); } - process.destroy(); lastTime = Time.monotonicNow(); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/ContainerLocalizer.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/ContainerLocalizer.java index 04be631..57f8c39 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/ContainerLocalizer.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/ContainerLocalizer.java @@ -184,7 +184,8 @@ public LocalizationProtocol run() { } finally { try { if (exec != null) { - exec.shutdownNow(); + exec.shutdown(); + exec.awaitTermination(10, TimeUnit.SECONDS); } LocalDirAllocator.removeContext(appCacheDirContextName); } finally {