The REPL process started by Calva remains when VS Code is exited
Issue Type: Bug
see here https://stackoverflow.com/questions/71011227/calva-how-to-stop-the-repl/71081092?noredirect=1#comment125656478_71081092
start vs code in a clojure project use calva jack-in command to start a repl quit visual stutio -> the repl is still running
Extension version: 2.0.243 VS Code version: Code 1.64.2 (f80445acd5a3dadef24aa209168452a3d97cc326, 2022-02-09T22:02:29.527Z) OS version: Linux x64 5.13.0-28-generic Restricted Mode: No
System Info
| Item | Value |
|---|---|
| CPUs | 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz (4 x 2803) |
| GPU Status | 2d_canvas: unavailable_software gpu_compositing: disabled_software multiple_raster_threads: enabled_on oop_rasterization: disabled_off opengl: disabled_off rasterization: disabled_software skia_renderer: enabled_on video_decode: disabled_software vulkan: disabled_off webgl: unavailable_software webgl2: unavailable_software |
| Load (avg) | 2, 2, 2 |
| Memory (System) | 7.77GB (0.14GB free) |
| Process Argv | . --crash-reporter-id 868e2e3c-2f8b-492e-8ac8-15f7be763e3d |
| Screen Reader | no |
| VM | 100% |
| DESKTOP_SESSION | ubuntu |
| XDG_CURRENT_DESKTOP | Unity |
| XDG_SESSION_DESKTOP | ubuntu |
| XDG_SESSION_TYPE | x11 |
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
pythonvspyl392:30425749
pythontb:30283811
pythonptprofiler:30281270
vsdfh931cf:30280410
vshan820:30294714
vstes263:30335439
pythondataviewer:30285071
vscod805:30301674
pythonvspyt200:30340761
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593cf:30376535
vsc1dst:30438360
pythonvs932:30410667
wslgetstarted:30433507
vsclayoutctrt:30437039
vsrem710:30416614
dsvsc008:30440022
vsbas813:30436447
vscscmwlcmt:30438805
helix:30438806
Thanks for this issue. Can you help investigate a bit if there are issues on VS Code about this? It is very probably an upstream thing.
@PEZ I can't see any issues on VS code relating to this. I can see that when I'm in vs code and start the REPL, there is a tree of processes like this (on linux)
systemd
gnome-shell
/usr/share/code/code
betterthantomorrow.calva-2.0.267/clojure-lsp
/bin/sh -c lein
/bin/bash /usr/bin/lein
java ... -m leiningen.core.main
java -classpath <my source dir>
after I quit vscode, the tree looks like this
systemd
/bin/sh -c lein
/bin/bash /usr/bin/lein
java ... -m leiningen.core.main
java -classpath <my source dir>
It looks like when calva is terminated, it doesn't terminate the lein subprocess, so that gets orphaned and picked up by systemd
From my vague long-term memory this is something to do with the way that SIGHUP is used to kill processes associated with a terminal window when the terminal exits. I think you're supposed to intercept SIGHUP and send it to any child processes before exiting yourself.
Thanks. Can you check if any processes get orphaned if you press ctrl+c in the jack-in terminal?
Yes pressing control-c kills all the processes (don't know why I never tried that before).
I also noticed something which I think may be significant - when I start the repl using the "jack in" command, the processes above are not associated to a TTY (i.e. they are not in a terminal as far as the OS is concerned) even though vs code shows the output in the terminal tab.
If I go into a vs code bash terminal window and type lein repl then use calva to connect to it, the processes are associated to the tty, and they get killed when I exit vs code.
I think this is related to the SIGHUP thing. When a terminal window closes, all its children are sent a SIGHUP (which normally will kill them), but non-tty processes do not get that behaviour.
Thanks for confirming. This works on Mac and my Linux box is not playing with me right now, so I can't try reproduce it here.
The Jack-in terminal is not a real terminal, indeed. It is a managed process using the vscode PseudoTerminal API. The API doesn't really provide any SIGHUP control. Afaiu we implement the API for killing the process when the window is closed or VS Code is shut down. I could be wrong, it was a while since I wrote this code. If you like, and since you can reproduce the problem, please feel invited to run Calva in dev mode and see if you can figure out what we could do here. See https://github.com/BetterThanTomorrow/calva/wiki/How-to-Hack-on-Calva for how to set the dev environment up (it's pretty straight forward and quick to do). The most relevant file to look at is src/nrepl/jack-in-terminal.ts.
Thanks Peter - I'm surprised to see that the problem doesn't happen on OSX because that's basically Unix.
Clojure is still a hobby project for me so this will have to take a back seat for a minute as I'm busy on some other work. However, I did have a quick look at the code and I noticed that kill accepts a signal parameter which we're currently not sending. If I get a chance to get the dev environment running I'll try passing in SIGHUP to see if that makes any difference.