Skip to content
Snippets Groups Projects
Commit 83fe3b5e authored by vinodkc's avatar vinodkc Committed by Sean Owen
Browse files

[SPARK-21665][CORE] Need to close resources after use

## What changes were proposed in this pull request?
Resources in Core - SparkSubmitArguments.scala, Spark-launcher - AbstractCommandBuilder.java, resource-managers- YARN - Client.scala are released

## How was this patch tested?
No new test cases added, Unit test have been passed

Author: vinodkc <vinod.kc.in@gmail.com>

Closes #18880 from vinodkc/br_fixresouceleak.
parent 6426adff
No related branches found
No related tags found
No related merge requests found
...@@ -207,11 +207,12 @@ private[deploy] class SparkSubmitArguments(args: Seq[String], env: Map[String, S ...@@ -207,11 +207,12 @@ private[deploy] class SparkSubmitArguments(args: Seq[String], env: Map[String, S
uriScheme match { uriScheme match {
case "file" => case "file" =>
try { try {
val jar = new JarFile(uri.getPath) Utils.tryWithResource(new JarFile(uri.getPath)) { jar =>
// Note that this might still return null if no main-class is set; we catch that later // Note that this might still return null if no main-class is set; we catch that later
mainClass = jar.getManifest.getMainAttributes.getValue("Main-Class") mainClass = jar.getManifest.getMainAttributes.getValue("Main-Class")
}
} catch { } catch {
case e: Exception => case _: Exception =>
SparkSubmit.printErrorAndExit(s"Cannot load main class from JAR $primaryResource") SparkSubmit.printErrorAndExit(s"Cannot load main class from JAR $primaryResource")
} }
case _ => case _ =>
......
...@@ -291,24 +291,14 @@ abstract class AbstractCommandBuilder { ...@@ -291,24 +291,14 @@ abstract class AbstractCommandBuilder {
} }
if (propsFile.isFile()) { if (propsFile.isFile()) {
FileInputStream fd = null; try (InputStreamReader isr = new InputStreamReader(
try { new FileInputStream(propsFile), StandardCharsets.UTF_8)) {
fd = new FileInputStream(propsFile); props.load(isr);
props.load(new InputStreamReader(fd, StandardCharsets.UTF_8));
for (Map.Entry<Object, Object> e : props.entrySet()) { for (Map.Entry<Object, Object> e : props.entrySet()) {
e.setValue(e.getValue().toString().trim()); e.setValue(e.getValue().toString().trim());
} }
} finally {
if (fd != null) {
try {
fd.close();
} catch (IOException e) {
// Ignore.
}
}
} }
} }
return props; return props;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment