Skip to content

Commit 1df3e82

Browse files
pzzsrxin
authored andcommitted
[SPARK-11974][CORE] Not all the temp dirs had been deleted when the JVM exits
deleting the temp dir like that ``` scala> import scala.collection.mutable import scala.collection.mutable scala> val a = mutable.Set(1,2,3,4,7,0,8,98,9) a: scala.collection.mutable.Set[Int] = Set(0, 9, 1, 2, 3, 7, 4, 8, 98) scala> a.foreach(x => {a.remove(x) }) scala> a.foreach(println(_)) 98 ``` You may not modify a collection while traversing or iterating over it.This can not delete all element of the collection Author: Zhongshuai Pei <peizhongshuai@huawei.com> Closes apache#9951 from DoingDone9/Bug_RemainDir. (cherry picked from commit 6b78157) Signed-off-by: Reynold Xin <rxin@databricks.com>
1 parent 94789f3 commit 1df3e82

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

core/src/main/scala/org/apache/spark/util/ShutdownHookManager.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ private[spark] object ShutdownHookManager extends Logging {
5757
// Add a shutdown hook to delete the temp dirs when the JVM exits
5858
addShutdownHook(TEMP_DIR_SHUTDOWN_PRIORITY) { () =>
5959
logInfo("Shutdown hook called")
60-
shutdownDeletePaths.foreach { dirPath =>
60+
// we need to materialize the paths to delete because deleteRecursively removes items from
61+
// shutdownDeletePaths as we are traversing through it.
62+
shutdownDeletePaths.toArray.foreach { dirPath =>
6163
try {
6264
logInfo("Deleting directory " + dirPath)
6365
Utils.deleteRecursively(new File(dirPath))

0 commit comments

Comments
 (0)