Skip to content

Commit

Permalink
[SPARK-21665][CORE] Need to close resources after use
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
vinodkc authored and srowen committed Aug 9, 2017
1 parent 6426adf commit 83fe3b5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
Expand Up @@ -207,11 +207,12 @@ private[deploy] class SparkSubmitArguments(args: Seq[String], env: Map[String, S
uriScheme match {
case "file" =>
try {
val jar = new JarFile(uri.getPath)
// Note that this might still return null if no main-class is set; we catch that later
mainClass = jar.getManifest.getMainAttributes.getValue("Main-Class")
Utils.tryWithResource(new JarFile(uri.getPath)) { jar =>
// Note that this might still return null if no main-class is set; we catch that later
mainClass = jar.getManifest.getMainAttributes.getValue("Main-Class")
}
} catch {
case e: Exception =>
case _: Exception =>
SparkSubmit.printErrorAndExit(s"Cannot load main class from JAR $primaryResource")
}
case _ =>
Expand Down
Expand Up @@ -291,24 +291,14 @@ private Properties loadPropertiesFile() throws IOException {
}

if (propsFile.isFile()) {
FileInputStream fd = null;
try {
fd = new FileInputStream(propsFile);
props.load(new InputStreamReader(fd, StandardCharsets.UTF_8));
try (InputStreamReader isr = new InputStreamReader(
new FileInputStream(propsFile), StandardCharsets.UTF_8)) {
props.load(isr);
for (Map.Entry<Object, Object> e : props.entrySet()) {
e.setValue(e.getValue().toString().trim());
}
} finally {
if (fd != null) {
try {
fd.close();
} catch (IOException e) {
// Ignore.
}
}
}
}

return props;
}

Expand Down

0 comments on commit 83fe3b5

Please sign in to comment.