Skip to content

Commit 4d30961

Browse files
xihuan_mstrHyukjinKwon
authored andcommitted
[SPARK-54753][SQL][4.0] Fix memory leak of ArtifactManager
### What changes were proposed in this pull request? backport the fix in trunk branch to branch-4.0 5b5ff6d dongjoon-hyun pranavdev022 hvanhovell vicennial HyukjinKwon cc Ngone51 LuciferYang ### Why are the changes needed? ### Does this PR introduce _any_ user-facing change? ### How was this patch tested? ### Was this patch authored or co-authored using generative AI tooling? Closes #53653 from scottme/SPARK-54753-4.0. Authored-by: xihuan_mstr <[email protected]> Signed-off-by: Hyukjin Kwon <[email protected]>
1 parent 2fc65e1 commit 4d30961

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

sql/connect/client/jvm/src/test/scala/org/apache/spark/sql/connect/client/CheckConnectJvmClientCompatibility.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ object CheckConnectJvmClientCompatibility {
234234
"org.apache.spark.sql.artifact.ArtifactManager$"),
235235
ProblemFilters.exclude[MissingClassProblem](
236236
"org.apache.spark.sql.artifact.ArtifactManager$SparkContextResourceType$"),
237+
ProblemFilters.exclude[MissingClassProblem](
238+
"org.apache.spark.sql.artifact.ArtifactManager$StateCleanupRunner"),
237239

238240
// ColumnNode conversions
239241
ProblemFilters.exclude[MissingTypesProblem]("org.apache.spark.sql.SparkSession"),

sql/core/src/main/scala/org/apache/spark/sql/artifact/ArtifactManager.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,7 @@ class ArtifactManager(session: SparkSession) extends AutoCloseable with Logging
384384
artifactPath)
385385
// Ensure that no reference to `this` is captured/help by the cleanup lambda
386386
private def getCleanable: Cleaner.Cleanable = cleaner.register(
387-
this,
388-
() => ArtifactManager.cleanUpGlobalResources(cleanUpStateForGlobalResources)
387+
this, new StateCleanupRunner(cleanUpStateForGlobalResources)
389388
)
390389
private var cleanable = getCleanable
391390

@@ -491,6 +490,12 @@ object ArtifactManager extends Logging {
491490
}
492491
}
493492

493+
private class StateCleanupRunner(cleanupState: ArtifactStateForCleanup) extends Runnable {
494+
override def run(): Unit = {
495+
ArtifactManager.cleanUpGlobalResources(cleanupState)
496+
}
497+
}
498+
494499
// Shared cleaner instance
495500
private val cleaner: Cleaner = Cleaner.create()
496501

0 commit comments

Comments
 (0)