Skip to content

Commit

Permalink
bugfix: Remove all cancallables on finish
Browse files Browse the repository at this point in the history
There were two remaining cases where cancllables were never removed from a queue:
- in shell runner
- debug sessions

Now, they are properly removed after finishing.

Follow up to #4421
  • Loading branch information
tgodzik committed Sep 23, 2022
1 parent de34e01 commit 0289b20
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 23 deletions.
Expand Up @@ -116,9 +116,9 @@ class ShellRunner(
ps.cancel
}
}
cancelables
.add(() => ps.cancel)
.add(() => taskResponse.cancel(false))
val newCancelables: List[Cancelable] =
List(() => ps.cancel, () => taskResponse.cancel(false))
newCancelables.foreach(cancelables.add)

val processFuture = ps.complete
statusBar.trackFuture(
Expand All @@ -131,6 +131,7 @@ class ShellRunner(
scribe.info(s"time: ran '$commandRun' in $elapsed")
result.trySuccess(code)
}
result.future.onComplete(_ => newCancelables.foreach(cancelables.remove))
result.future
}

Expand Down
Expand Up @@ -133,8 +133,9 @@ class MetalsLanguageServer(
case Some(session) => session.shutdown()
case None => Future.successful(())
}
try cancelables.cancel()
catch {
try {
cancelables.cancel()
} catch {
case NonFatal(_) =>
}
try buildShutdown.asJava.get(100, TimeUnit.MILLISECONDS)
Expand Down Expand Up @@ -699,21 +700,23 @@ class MetalsLanguageServer(
sourceMapper,
)
)
debugProvider = new DebugProvider(
workspace,
definitionProvider,
buildTargets,
buildTargetClasses,
compilations,
languageClient,
buildClient,
classFinder,
definitionIndex,
stacktraceAnalyzer,
clientConfig,
semanticdbs,
compilers,
statusBar,
debugProvider = register(
new DebugProvider(
workspace,
definitionProvider,
buildTargets,
buildTargetClasses,
compilations,
languageClient,
buildClient,
classFinder,
definitionIndex,
stacktraceAnalyzer,
clientConfig,
semanticdbs,
compilers,
statusBar,
)
)
scalafixProvider = ScalafixProvider(
buffers,
Expand Down Expand Up @@ -1972,7 +1975,6 @@ class MetalsLanguageServer(
)
} yield {
statusBar.addMessage("Started debug server!")
cancelables.add(server)
DebugSession(server.sessionName, server.uri.toString)
}
session.asJavaObject
Expand Down
Expand Up @@ -20,6 +20,7 @@ import scala.util.control.NonFatal

import scala.meta.internal.metals.BuildServerConnection
import scala.meta.internal.metals.BuildTargets
import scala.meta.internal.metals.Cancelable
import scala.meta.internal.metals.ClientCommands
import scala.meta.internal.metals.ClientConfiguration
import scala.meta.internal.metals.Compilations
Expand All @@ -35,6 +36,7 @@ import scala.meta.internal.metals.Messages
import scala.meta.internal.metals.Messages.UnresolvedDebugSessionParams
import scala.meta.internal.metals.MetalsBuildClient
import scala.meta.internal.metals.MetalsEnrichments._
import scala.meta.internal.metals.MutableCancelable
import scala.meta.internal.metals.ScalaTestSuites
import scala.meta.internal.metals.ScalaTestSuitesDebugRequest
import scala.meta.internal.metals.ScalaVersionSelector
Expand Down Expand Up @@ -84,10 +86,14 @@ class DebugProvider(
semanticdbs: Semanticdbs,
compilers: Compilers,
statusBar: StatusBar,
) {
) extends Cancelable {

import DebugProvider._

private val debugSessions = new MutableCancelable()

override def cancel(): Unit = debugSessions.cancel()

lazy val buildTargetClassesFinder = new BuildTargetClassesFinder(
buildTargets,
buildTargetClasses,
Expand Down Expand Up @@ -185,7 +191,11 @@ class DebugProvider(
}
val server = new DebugServer(sessionName, uri, proxyFactory)

server.listen.andThen { case _ => proxyServer.close() }
debugSessions.add(server)
server.listen.andThen { case _ =>
proxyServer.close()
debugSessions.remove(server)
}

connectedToServer.future.map(_ => server)
}
Expand Down

0 comments on commit 0289b20

Please sign in to comment.