[ 
https://issues.apache.org/jira/browse/SPARK-56276?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

ASF GitHub Bot updated SPARK-56276:
-----------------------------------
    Labels: pull-request-available  (was: )

> Fix file descriptor leak in SparkAppResourceSpecFactory
> -------------------------------------------------------
>
>                 Key: SPARK-56276
>                 URL: https://issues.apache.org/jira/browse/SPARK-56276
>             Project: Spark
>          Issue Type: Improvement
>          Components: Kubernetes
>    Affects Versions: kubernetes-operator-0.9.0
>            Reporter: Jiwon Park
>            Priority: Minor
>              Labels: pull-request-available
>
> In {{SparkAppResourceSpecFactory.createLocalFileForPodTemplateSpec()}}, 
> {{FileOutputStream}} and {{OutputStreamWriter}} are opened without 
> try-with-resources:
> {code:java}
> FileOutputStream fileStream = new FileOutputStream(tmpFile);
> OutputStreamWriter writer = new OutputStreamWriter(fileStream, "UTF-8");
> writer.write(ModelUtils.asJsonString(ModelUtils.getPodFromTemplateSpec(podTemplateSpec)));
> writer.close();
> {code}
> If {{writer.write()}} or {{ModelUtils.asJsonString()}} throws an exception, 
> {{writer.close()}} is never reached and the file descriptors remain open. In 
> long-running operator deployments this can gradually exhaust the OS file 
> descriptor limit.
> Additionally, {{deleteLocalFileFromPathKey()}} catches {{Throwable}}, which 
> swallows JVM-level errors such as {{OutOfMemoryError}} and 
> {{VirtualMachineError}}. Only {{SecurityException}} can actually be thrown by 
> {{File.delete()}}.
> *Fix:* Wrap the writer in a try-with-resources block so it is always closed, 
> replace the {{\"UTF-8\"}} string literal with {{StandardCharsets.UTF_8}}, and 
> narrow the catch clause from {{Throwable}} to {{SecurityException}}.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to