You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "mridulm (via GitHub)" <gi...@apache.org> on 2024/12/15 16:35:53 UTC
Re: [PR] [SPARK-49980][CORE][SQL] Fix potential file stream leaks caused by interruption in canceled tasks [spark]
mridulm commented on code in PR #48483:
URL: https://github.com/apache/spark/pull/48483#discussion_r1885759273
##########
common/utils/src/main/scala/org/apache/spark/util/SparkErrorUtils.scala:
##########
@@ -48,6 +48,22 @@ private[spark] trait SparkErrorUtils extends Logging {
try f.apply(resource) finally resource.close()
}
+ /**
+ * Try to initialize a resource. If an exception is throw during initialization, closes the
+ * resource before propagating the error. Otherwise, the caller is responsible for closing
+ * the resource. This means that [[T]] should provide some way to close the resource.
+ */
+ def tryInitializeResource[R <: Closeable, T](createResource: => R)(initialize: R => T): T = {
+ val resource = createResource
+ try {
+ initialize(resource)
+ } catch {
+ case e: Throwable =>
+ resource.close()
+ throw e
Review Comment:
If `close` results in an `IOException`, `e` will be lost - we should catch and add it via `addSuppressed`.
Do you want to create a follow up PR for this @davintjong-db ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org