aboutsummaryrefslogtreecommitdiff
path: root/streaming/src/test
diff options
context:
space:
mode:
authorJosh Rosen <joshrosen@databricks.com>2015-11-18 16:00:35 -0800
committerReynold Xin <rxin@databricks.com>2015-11-18 16:00:35 -0800
commit4b117121900e5f242e7c8f46a69164385f0da7cc (patch)
tree3134b152d511565a7bc4ba7b2cc8e61f859a9f2a /streaming/src/test
parentc07a50b86254578625be777b1890ff95e832ac6e (diff)
downloadspark-4b117121900e5f242e7c8f46a69164385f0da7cc.tar.gz
spark-4b117121900e5f242e7c8f46a69164385f0da7cc.tar.bz2
spark-4b117121900e5f242e7c8f46a69164385f0da7cc.zip
[SPARK-11495] Fix potential socket / file handle leaks that were found via static analysis
The HP Fortify Opens Source Review team (https://www.hpfod.com/open-source-review-project) reported a handful of potential resource leaks that were discovered using their static analysis tool. We should fix the issues identified by their scan. Author: Josh Rosen <joshrosen@databricks.com> Closes #9455 from JoshRosen/fix-potential-resource-leaks.
Diffstat (limited to 'streaming/src/test')
-rw-r--r--streaming/src/test/java/org/apache/spark/streaming/JavaReceiverAPISuite.java20
1 files changed, 13 insertions, 7 deletions
diff --git a/streaming/src/test/java/org/apache/spark/streaming/JavaReceiverAPISuite.java b/streaming/src/test/java/org/apache/spark/streaming/JavaReceiverAPISuite.java
index ec2bffd6a5..7a8ef9d147 100644
--- a/streaming/src/test/java/org/apache/spark/streaming/JavaReceiverAPISuite.java
+++ b/streaming/src/test/java/org/apache/spark/streaming/JavaReceiverAPISuite.java
@@ -23,6 +23,7 @@ import org.apache.spark.streaming.api.java.JavaReceiverInputDStream;
import org.apache.spark.streaming.api.java.JavaStreamingContext;
import static org.junit.Assert.*;
+import com.google.common.io.Closeables;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -121,14 +122,19 @@ public class JavaReceiverAPISuite implements Serializable {
private void receive() {
try {
- Socket socket = new Socket(host, port);
- BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- String userInput;
- while ((userInput = in.readLine()) != null) {
- store(userInput);
+ Socket socket = null;
+ BufferedReader in = null;
+ try {
+ socket = new Socket(host, port);
+ in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ String userInput;
+ while ((userInput = in.readLine()) != null) {
+ store(userInput);
+ }
+ } finally {
+ Closeables.close(in, /* swallowIOException = */ true);
+ Closeables.close(socket, /* swallowIOException = */ true);
}
- in.close();
- socket.close();
} catch(ConnectException ce) {
ce.printStackTrace();
restart("Could not connect", ce);