Author: daryn
Date: Thu Jan 16 18:57:55 2014
New Revision: 1558886
URL: http://svn.apache.org/r1558886
Log:
HADOOP-10146. Workaround JDK7 Process fd close bug (daryn)
Modified:
hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt
hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java
Modified:
hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1558886&r1=1558885&r2=1558886&view=diff
==============================================================================
---
hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt
(original)
+++
hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt
Thu Jan 16 18:57:55 2014
@@ -19,6 +19,8 @@ Release 0.23.11 - UNRELEASED
HADOOP-10081. Client.setupIOStreams can leak socket resources on exception
or error (Tsuyoshi OZAWA via jlowe)
+ HADOOP-10146. Workaround JDK7 Process fd close bug (daryn)
+
Release 0.23.10 - 2013-12-09
INCOMPATIBLE CHANGES
Modified:
hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java
URL:
http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java?rev=1558886&r1=1558885&r2=1558886&view=diff
==============================================================================
---
hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java
(original)
+++
hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java
Thu Jan 16 18:57:55 2014
@@ -20,6 +20,7 @@ package org.apache.hadoop.util;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.Timer;
@@ -210,7 +211,17 @@ abstract public class Shell {
}
// close the input stream
try {
- inReader.close();
+ // JDK 7 tries to automatically drain the input streams for us
+ // when the process exits, but since close is not synchronized,
+ // it creates a race if we close the stream first and the same
+ // fd is recycled. the stream draining thread will attempt to
+ // drain that fd!! it may block, OOM, or cause bizarre behavior
+ // see: https://bugs.openjdk.java.net/browse/JDK-8024521
+ // issue is fixed in build 7u60
+ InputStream stdout = process.getInputStream();
+ synchronized (stdout) {
+ inReader.close();
+ }
} catch (IOException ioe) {
LOG.warn("Error while closing the input stream", ioe);
}
@@ -218,7 +229,10 @@ abstract public class Shell {
errThread.interrupt();
}
try {
- errReader.close();
+ InputStream stderr = process.getErrorStream();
+ synchronized (stderr) {
+ errReader.close();
+ }
} catch (IOException ioe) {
LOG.warn("Error while closing the error stream", ioe);
}