scalameta / metals

Scala language server with rich IDE features 🚀
https://scalameta.org/metals/
Apache License 2.0
2.07k stars 323 forks source link

many bloop processes cause `sbt bloopInstall` to fail without helpful message. #5303

Open i10416 opened 1 year ago

i10416 commented 1 year ago

Describe the bug

When there are many bloop processes [^1] running[^2], sbt bloopInstall silently fails, which prevent most of metals features(e.g. rename, completion, jump to definition, etc.) from working, due to connection failure to bloop server. However, it emits misleading logs like No build target found for ....

After killing bloop processes by kill -p <id>, metals works fine.

Can metals emit more helpful logs when it fails to start because of many other bloop processes running?

[^1]: NOTE: I don't check how many bloop instances will cause this error. [^2]: As far as I know, there can be one instance of bloop on a machine https://scalacenter.github.io/bloop/docs/what-is-bloop#limitations

Expected behavior

  1. Can Metals emit more helpful logs when it fails to start because of many other bloop processes running?
  2. Can we prevent Metals from launching bloop when there has already been a running instance, or at least detect it and give some warnings to users?

Operating system

macOS

Editor/Extension

VS Code

Version of Metals

v.0.11.12

Extra context or search terms

Search terms

related issues

https://github.com/scalameta/metals/issues/1028

tgodzik commented 1 year ago

Sorry for just coming back to it. What was the exact log message that led you to kill Bloop? We never start more than one, but I've seen a situation where there was a zombie process running. We could potentially fix this by automatic shutdown and named sockets, but I don't think killing a user's process is a good idea. We try to point to that, but it might be hard to figure it out

i10416 commented 1 year ago

What was the exact log message that led you to kill Bloop?

Sorry, I don't exactly remember the log message, but the log message is something like No build target for ....

So, I searched for similar issues and found https://github.com/scalameta/metals/issues/1697, which is mainly about java.lang.RuntimeException: The server did not start, got FailedToOpenBspConnection.

Though I couldn't find any error message like The server did not start, got FailedToOpenBspConnection on my local machine, other people posts error logs that contains WARN no build target... and I also found your comment suggesting killing bloop process which gains some upvotes.

I found where were multiple bloop processes running.

Thus, I tried killing bloop process and then metals started working fine.

I don't think killing a user's process is a good idea.

I agree with you.

i10416 commented 1 year ago

I get into similar situation and I found the following logs this time.

2023.07.06 12:38:53 WARN  no build target for: /path/to/project/plugins.sbt
2023.07.06 12:38:53 WARN  no build target for: /path/to/project/metals.sbt
2023.07.06 12:38:53 WARN  no build target for: /path/to/build.sbt
2023.07.06 12:39:26 ERROR Starting the bsp launcher for bloop...
2023.07.06 12:39:26 ERROR Opening a bsp server connection with 'bsp --protocol local --socket /var/folders/25/j44kzkh50lncdcbqnp57jfbc0000gn/T/bsp-launcher1391556547030299436/bsp.socket'...
2023.07.06 12:39:26 ERROR Waiting for the bsp connection to come up...
2023.07.06 12:39:26 ERROR Waiting for the bsp connection to come up...
2023.07.06 12:39:26 ERROR Waiting for the bsp connection to come up...
2023.07.06 12:39:26 ERROR Waiting for the bsp connection to come up...
....
....
2023.07.06 12:39:26 ERROR error: Giving up on waiting for a connection, printing embedded bloop logs:
2023.07.06 12:39:26 ERROR > 
2023.07.06 12:39:26 ERROR error: Trying a tcp-based connection to the server instead...
2023.07.06 12:39:26 ERROR Opening a bsp server connection with 'bsp --protocol tcp --port 32028'...
2023.07.06 12:39:26 ERROR Waiting for the bsp connection to come up...
2023.07.06 12:39:26 ERROR Waiting for the bsp connection to come up...
2023.07.06 12:39:26 ERROR Waiting for the bsp connection to come up...
...
...
2023.07.06 12:39:26 ERROR error: Giving up on waiting for a connection, printing embedded bloop logs:
2023.07.06 12:39:26 ERROR > 
2023.07.06 12:39:26 ERROR error: The launcher failed to establish a bsp connection, aborting...
2023.07.06 12:39:26 ERROR Failed to connect with build server, no functionality will work.
java.lang.RuntimeException: The server did not start, got FailedToOpenBspConnection
    at bloop.launcher.LauncherMain.failPromise$1(Launcher.scala:92)
    at bloop.launcher.LauncherMain.runLauncher(Launcher.scala:119)
    at scala.meta.internal.metals.BloopServers$$anon$2.run(BloopServers.scala:496)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
    at java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.lang.Thread.run(Thread.java:833)