Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bsp server launched from console is not terminated when parent process is terminated #7094

Open
unkarjedy opened this issue Dec 20, 2022 · 2 comments
Labels

Comments

@unkarjedy
Copy link
Contributor

unkarjedy commented Dec 20, 2022

(I am on Windows)

  1. Start server from console using this command:
~/.jdks/corretto-18.0.2/bin/java \
    -Xms100m  \
    -Xmx100m  \
    -classpath ~/AppData/Local/Coursier/cache/v1/https/repo1.maven.org/maven2/org/scala-sbt/sbt-launch/1.8.0/sbt-launch-1.8.0.jar \
    xsbt.boot.Boot \
    -bsp \
    --sbt-launch-jar=~/AppData/Local/Coursier/cache/v1/https/repo1.maven.org/maven2/org/scala-sbt/sbt-launch/1.8.0/sbt-launch-1.8.0.jar

(substitute your home to ~, otherwise sbt doesn't understand it)

  1. Wait for the output:
[info] server was not detected. starting an instance
[warn] server is started using sbt-launch jar directly
[warn] this is not the recommended way: .sbtopts and .jvmopts files are not loaded and SBT_OPTS is ignored
[warn] either upgrade sbt.bat to its latest version or make sure it is accessible from $PATH, and run 'sbt bspConfig'
[info] welcome to sbt 1.8.0 (Amazon.com Inc. Java 18.0.2)
[info] loading global plugins from C:\Users\dmitrii.naumenko\.sbt\1.0\plugins
[info] loading project definition from C:\Users\dmitrii.naumenko\project
[info] set current project to dmitrii-naumenko (in build file:/C:/Users/dmitrii.naumenko/)
[info] sbt server started at local:sbt-server-3c9af2a7955490544b47
[info] started sbt server

Notice that two processes are launched:
The first corresponds to the JVM we just launched
Second, it's child:

~/.jdks/corretto-18.0.2/bin/java \
    -Dsbt.io.virtual=true \
    -jar ~/AppData/Local/Coursier/cache/v1/https/repo1.maven.org/maven2/org/scala-sbt/sbt-launch/1.8.0/sbt-launch-1.8.0.jar \
    --detach-stdio \
    --server
  1. Terminate the process via Ctrl + C

Actual result
The child process isn't terminated, it remains hanging.
You need to kill it via process explorer.

Expected result
I am not that experienced in BSP but to me, it seems like a strange, not practical default behavior.

If after starting the main process it doesn't quit immediately I would expect that killing it would also kill the child server process.
While trying to debug various issues with IntelliJ-BSP integration I constantly had to kill processes from process explorer dozens of times.

What's more - AFAIU there is no way to disable this behavior because --detach-stdio is hard-coded in sbt.internal.client.NetworkClient#waitForServer and the comment says:

This instance must be shutdown explicitly via sbt -client shutdown
But this also doesn't work: #6723

It would be nice if the default behavior killed the child sbt server process

cc @jastice

@unkarjedy unkarjedy added the Bug label Dec 20, 2022
@eed3si9n
Copy link
Member

Thanks for the report.
This is somewhat complicated topic, but one motivation of having the sbt server in general is to speed up the perceived load time by having the server always running. This allows interaction via sbtn client from shell issueing one command at a time.

I think there's a setting somewhere to control the idle TTL (time to live). I wonder if that should be set to 0s for BSP?

@unkarjedy
Copy link
Contributor Author

@eed3si9n
I would like to clarify some points, including terminology, just to be on the same page in the future.

As I mentioned, when I start the process ("process1") from a command line generated in .bsp/sbt.json (with xsbt.boot.Boot -bsp) it forks a child process ("process2", with --detach-stdio --server).
What are the correct terms for both of the processes?
AFAIU "process2" is at the same time a BSP server and SBT server:
I can connect to it via sbtn --client and send sbt commands.
At the same time I can connect to it via BSP client (e.g. from IntelliJ)
Is that correct?
If so, then what is then "process1" for?
Can't we skip forking another process and just start the combined SBT/BSP server in the original process when passing -bsp?
Or if the proper command to start BSP server is just --detach-stdio --server can we use it directly in .bsp/sbt.json?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants