From c66f31d8a1404eb99ea7038aeffc2922a0812725 Mon Sep 17 00:00:00 2001 From: Ethan Atkins Date: Sun, 25 Oct 2020 15:07:24 -0700 Subject: [PATCH] Avoid throwing interrupted exception in JoinThread I saw a stacktrace when exiting sbtn on windows due to an interrupted exception being thrown during thread joining. We only want to throw this exception if we didn't successfully join the thread. I also noticed that we would try to join the thread forever. There was supposed to be a timelimit so that we would eventually stop blocking even if we were unable to join the thread. The limit was set but not respected. --- .../src/main/scala/sbt/internal/util/JoinThread.scala | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/main-command/src/main/scala/sbt/internal/util/JoinThread.scala b/main-command/src/main/scala/sbt/internal/util/JoinThread.scala index e2bee2f07..0f70a902e 100644 --- a/main-command/src/main/scala/sbt/internal/util/JoinThread.scala +++ b/main-command/src/main/scala/sbt/internal/util/JoinThread.scala @@ -20,11 +20,13 @@ object JoinThread { t.interrupt() t.join(10) } catch { case e: InterruptedException => exception = Some(e) } - if (t.isAlive) impl() + if (t.isAlive && !deadline.isOverdue) impl() } impl() - if (t.isAlive) System.err.println(s"Unable to join thread $t after $duration") - exception.foreach(throw _) + if (t.isAlive) { + System.err.println(s"Unable to join thread $t after $duration") + exception.foreach(throw _) + } } } }