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 na...@apache.org on 2016/10/28 00:29:09 UTC
hadoop git commit: MAPREDUCE-2631. Potential resource leaks in
BinaryProtocol$TeeOutputStream.java. Contributed by Sunil G.
Repository: hadoop
Updated Branches:
refs/heads/trunk 5877f20f9 -> 28660f51a
MAPREDUCE-2631. Potential resource leaks in BinaryProtocol$TeeOutputStream.java. Contributed by Sunil G.
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/28660f51
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/28660f51
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/28660f51
Branch: refs/heads/trunk
Commit: 28660f51af161a9fa301523d96a6f8ae4ebd6edd
Parents: 5877f20
Author: Naganarasimha <na...@apache.org>
Authored: Fri Oct 28 05:50:13 2016 +0530
Committer: Naganarasimha <na...@apache.org>
Committed: Fri Oct 28 05:50:13 2016 +0530
----------------------------------------------------------------------
.../apache/hadoop/mapred/IFileOutputStream.java | 8 ++++++--
.../hadoop/mapred/pipes/BinaryProtocol.java | 14 +++++++++-----
.../apache/hadoop/mapred/TestIFileStreams.java | 20 ++++++++++++++++++++
3 files changed, 35 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hadoop/blob/28660f51/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/IFileOutputStream.java
----------------------------------------------------------------------
diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/IFileOutputStream.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/IFileOutputStream.java
index 8f25ba7..08bcd24 100644
--- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/IFileOutputStream.java
+++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/IFileOutputStream.java
@@ -24,6 +24,7 @@ import java.io.FilterOutputStream;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.util.DataChecksum;
/**
* A Checksum output stream.
@@ -60,8 +61,11 @@ public class IFileOutputStream extends FilterOutputStream {
return;
}
closed = true;
- finish();
- out.close();
+ try {
+ finish();
+ } finally {
+ IOUtils.closeStream(out);
+ }
}
/**
http://git-wip-us.apache.org/repos/asf/hadoop/blob/28660f51/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/pipes/BinaryProtocol.java
----------------------------------------------------------------------
diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/pipes/BinaryProtocol.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/pipes/BinaryProtocol.java
index ebfb184..5a3ed5b 100644
--- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/pipes/BinaryProtocol.java
+++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/pipes/BinaryProtocol.java
@@ -36,6 +36,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.io.BytesWritable;
import org.apache.hadoop.io.DataOutputBuffer;
+import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;
@@ -200,8 +201,8 @@ class BinaryProtocol<K1 extends WritableComparable, V1 extends Writable,
file = new FileOutputStream(filename);
}
public void write(byte b[], int off, int len) throws IOException {
- file.write(b,off,len);
- out.write(b,off,len);
+ file.write(b, off, len);
+ out.write(b, off, len);
}
public void write(int b) throws IOException {
@@ -215,9 +216,12 @@ class BinaryProtocol<K1 extends WritableComparable, V1 extends Writable,
}
public void close() throws IOException {
- flush();
- file.close();
- out.close();
+ try {
+ flush();
+ } finally {
+ IOUtils.closeStream(file);
+ IOUtils.closeStream(out);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/28660f51/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/TestIFileStreams.java
----------------------------------------------------------------------
diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/TestIFileStreams.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/TestIFileStreams.java
index 2b97d3b..a815b28 100644
--- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/TestIFileStreams.java
+++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/TestIFileStreams.java
@@ -22,7 +22,13 @@ import org.apache.hadoop.fs.ChecksumException;
import org.apache.hadoop.io.DataInputBuffer;
import org.apache.hadoop.io.DataOutputBuffer;
import org.junit.Test;
+import org.mockito.Mockito;
+
import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
import static org.junit.Assert.assertEquals;
public class TestIFileStreams {
@@ -99,4 +105,18 @@ public class TestIFileStreams {
fail("Did not detect bad data in checksum");
}
+ @Test
+ public void testCloseStreamOnException() throws Exception {
+ OutputStream outputStream = Mockito.mock(OutputStream.class);
+ IFileOutputStream ifos = new IFileOutputStream(outputStream);
+ Mockito.doThrow(new IOException("Dummy Exception")).when(outputStream)
+ .flush();
+ try {
+ ifos.close();
+ fail("IOException is not thrown");
+ } catch (IOException ioe) {
+ assertEquals("Dummy Exception", ioe.getMessage());
+ }
+ Mockito.verify(outputStream).close();
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org