From d12bb2d71e09ce95cab02a615401ddeeaeb4d435 Mon Sep 17 00:00:00 2001 From: Ethan Atkins Date: Sun, 6 Oct 2019 16:21:59 -0700 Subject: [PATCH] Shutdown progress thread when there are no tasks It is still possible for progress threads to leak so shut them down if there are no active tasks. The report0 method will start up a new thread if a task is added. --- main/src/main/scala/sbt/internal/TaskProgress.scala | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main/src/main/scala/sbt/internal/TaskProgress.scala b/main/src/main/scala/sbt/internal/TaskProgress.scala index ad7cf226e..4a91a0f01 100644 --- a/main/src/main/scala/sbt/internal/TaskProgress.scala +++ b/main/src/main/scala/sbt/internal/TaskProgress.scala @@ -35,6 +35,7 @@ private[sbt] final class TaskProgress(log: ManagedLogger) try { report() Thread.sleep(sleepDuration) + if (active.isEmpty) TaskProgress.this.stop() } catch { case _: InterruptedException => } @@ -58,7 +59,9 @@ private[sbt] final class TaskProgress(log: ManagedLogger) override def afterCompleted[A](task: Task[A], result: Result[A]): Unit = () - override def stop(): Unit = currentProgressThread.getAndSet(None).foreach(_.close()) + override def stop(): Unit = currentProgressThread.synchronized { + currentProgressThread.getAndSet(None).foreach(_.close()) + } override def afterAllCompleted(results: RMap[Task, Result]): Unit = { // send an empty progress report to clear out the previous report @@ -80,8 +83,9 @@ private[sbt] final class TaskProgress(log: ManagedLogger) case _ => } } + private[this] def active: Vector[Task[_]] = activeTasks.toVector.filterNot(Def.isDummy) private[this] def report(): Unit = { - val currentTasks = activeTasks.toVector.filterNot(Def.isDummy) + val currentTasks = active val ltc = lastTaskCount.get val currentTasksCount = currentTasks.size def report0(tasks: Vector[Task[_]]): Unit = {