From 2e208af7c129f87b690ce67133dc0b45fea5e2b1 Mon Sep 17 00:00:00 2001 From: Ethan Atkins Date: Thu, 3 Dec 2020 08:28:48 -0800 Subject: [PATCH] Close jline 3 terminal when console exits The jline 3 Terminal is an autocloseable and should be closed when we're down with it. I'm not exactly sure what resources we were potentially leaking, but the jline3term variable is an instance of the jline AbstractTerminal class which I know can create a thread in some circumstances. This came up while working on #6185. --- main-actions/src/main/scala/sbt/Console.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main-actions/src/main/scala/sbt/Console.scala b/main-actions/src/main/scala/sbt/Console.scala index d8ed6d730..a40c12a27 100644 --- a/main-actions/src/main/scala/sbt/Console.scala +++ b/main-actions/src/main/scala/sbt/Console.scala @@ -65,15 +65,17 @@ final class Console(compiler: AnalyzingCompiler) { ) } catch { case _: InterruptedException | _: ClosedChannelException => } val previous = sys.props.get("scala.color").getOrElse("auto") + val jline3term = sbt.internal.util.JLine3(terminal) try { sys.props("scala.color") = if (terminal.isColorEnabled) "true" else "false" terminal.withRawOutput { jline.TerminalFactory.set(terminal.toJLine) - DeprecatedJLine.setTerminalOverride(sbt.internal.util.JLine3(terminal)) + DeprecatedJLine.setTerminalOverride(jline3term) terminal.withRawInput(Run.executeTrapExit(console0, log)) } } finally { sys.props("scala.color") = previous + jline3term.close() } } }