You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ha...@apache.org on 2012/09/22 22:34:17 UTC
svn commit: r1388893 - in
/hadoop/common/trunk/hadoop-common-project/hadoop-common: CHANGES.txt
src/main/java/org/apache/hadoop/io/IOUtils.java
src/test/java/org/apache/hadoop/io/TestIOUtils.java
Author: harsh
Date: Sat Sep 22 20:34:16 2012
New Revision: 1388893
URL: http://svn.apache.org/viewvc?rev=1388893&view=rev
Log:
HADOOP-7256. Resource leak during failure scenario of closing of resources. Contributed by Ramkrishna S. Vasudevan. (harsh)
Modified:
hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/IOUtils.java
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestIOUtils.java
Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1388893&r1=1388892&r2=1388893&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt Sat Sep 22 20:34:16 2012
@@ -215,6 +215,9 @@ Trunk (Unreleased)
HADOOP-8821. Fix findbugs warning related to concatenating string in a
for loop in Configuration#dumpDeprecatedKeys(). (suresh)
+ HADOOP-7256. Resource leak during failure scenario of closing
+ of resources. (Ramkrishna S. Vasudevan via harsh)
+
OPTIMIZATIONS
HADOOP-7761. Improve the performance of raw comparisons. (todd)
Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/IOUtils.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/IOUtils.java?rev=1388893&r1=1388892&r2=1388893&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/IOUtils.java (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/IOUtils.java Sat Sep 22 20:34:16 2012
@@ -25,6 +25,7 @@ import java.nio.channels.FileChannel;
import java.nio.channels.WritableByteChannel;
import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
@@ -36,6 +37,7 @@ import org.apache.hadoop.conf.Configurat
@InterfaceAudience.Public
@InterfaceStability.Evolving
public class IOUtils {
+ public static final Log LOG = LogFactory.getLog(IOUtils.class);
/**
* Copies from one stream to another.
@@ -235,7 +237,7 @@ public class IOUtils {
if (c != null) {
try {
c.close();
- } catch(IOException e) {
+ } catch(Throwable e) {
if (log != null && log.isDebugEnabled()) {
log.debug("Exception in closing " + c, e);
}
@@ -264,6 +266,7 @@ public class IOUtils {
try {
sock.close();
} catch (IOException ignored) {
+ LOG.debug("Ignoring exception while closing socket", ignored);
}
}
}
Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestIOUtils.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestIOUtils.java?rev=1388893&r1=1388892&r2=1388893&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestIOUtils.java (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestIOUtils.java Sat Sep 22 20:34:16 2012
@@ -67,6 +67,36 @@ public class TestIOUtils {
}
@Test
+ public void testCopyBytesShouldCloseInputSteamWhenOutputStreamCloseThrowsRunTimeException()
+ throws Exception {
+ InputStream inputStream = Mockito.mock(InputStream.class);
+ OutputStream outputStream = Mockito.mock(OutputStream.class);
+ Mockito.doReturn(-1).when(inputStream).read(new byte[1]);
+ Mockito.doThrow(new RuntimeException()).when(outputStream).close();
+ try {
+ IOUtils.copyBytes(inputStream, outputStream, 1, true);
+ fail("Didn't throw exception");
+ } catch (RuntimeException e) {
+ }
+ Mockito.verify(outputStream, Mockito.atLeastOnce()).close();
+ }
+
+ @Test
+ public void testCopyBytesShouldCloseInputSteamWhenInputStreamCloseThrowsRunTimeException()
+ throws Exception {
+ InputStream inputStream = Mockito.mock(InputStream.class);
+ OutputStream outputStream = Mockito.mock(OutputStream.class);
+ Mockito.doReturn(-1).when(inputStream).read(new byte[1]);
+ Mockito.doThrow(new RuntimeException()).when(inputStream).close();
+ try {
+ IOUtils.copyBytes(inputStream, outputStream, 1, true);
+ fail("Didn't throw exception");
+ } catch (RuntimeException e) {
+ }
+ Mockito.verify(inputStream, Mockito.atLeastOnce()).close();
+ }
+
+ @Test
public void testCopyBytesShouldNotCloseStreamsWhenCloseIsFalse()
throws Exception {
InputStream inputStream = Mockito.mock(InputStream.class);
@@ -76,7 +106,7 @@ public class TestIOUtils {
Mockito.verify(inputStream, Mockito.atMost(0)).close();
Mockito.verify(outputStream, Mockito.atMost(0)).close();
}
-
+
@Test
public void testCopyBytesWithCountShouldCloseStreamsWhenCloseIsTrue()
throws Exception {
@@ -117,7 +147,7 @@ public class TestIOUtils {
Mockito.verify(inputStream, Mockito.atLeastOnce()).close();
Mockito.verify(outputStream, Mockito.atLeastOnce()).close();
}
-
+
@Test
public void testWriteFully() throws IOException {
final int INPUT_BUFFER_LEN = 10000;
@@ -148,6 +178,7 @@ public class TestIOUtils {
for (int i = HALFWAY; i < input.length; i++) {
assertEquals(input[i - HALFWAY], output[i]);
}
+ raf.close();
} finally {
File f = new File(TEST_FILE_NAME);
if (f.exists()) {
@@ -177,7 +208,7 @@ public class TestIOUtils {
"Error while reading compressed data", ioe);
}
}
-
+
@Test
public void testSkipFully() throws IOException {
byte inArray[] = new byte[] {0, 1, 2, 3, 4};