calva icon indicating copy to clipboard operation
calva copied to clipboard

Calva does not seem to kill the java processes created by running the REPL

Open gaelrech opened this issue 8 months ago • 8 comments

It seems that when we stop a REPL or when we close Cursor, the java processes spawned by the REPL are not killed.

I have not tested in VSCode, but I'm assuming it happens the same thing since I had such problems when I used it just never got the time to do a better investigation of it.

Cursor Version: 1.2.1 VSCode Version: 1.99.3 Calva Version: 2.0.520

Steps to reproduce:

  1. Run pgrep -l 'java|clojure'. There are no processes.
  2. Open Cursor
  3. It will show one clojure process for ~/.cursor/extensions/betterthantomorrow.calva-2.0.520-universal/clojure-lsp
  4. Close Cursor
  5. Run pgrep -l 'java|clojure'. Process is killed as expected. No processes for java or clojure.
  6. Open Cursor again
  7. Start a repl (calva.jackIn command)
  8. Run pgrep -l 'java|clojure'. It creates two java processes (in addition to the clojure-lsp one that is creating upon opening Cursor)
  9. Stop the repl (calva.disconnect).
  10. Run pgrep -l 'java|clojure'. The two java processes are still running.
  11. Close Cursor (via CMD+Q, in case it matters)
  12. Run pgrep -l 'java|clojure'. The clojure-lsp process was killed, but the two java processes are still there.
  13. Open Cursor
  14. Run pgrep -l 'java|clojure'. The clojure-lsp process was created again, the two java processes from before are still there.
  15. Start a repl
  16. Run pgrep -l 'java|clojure'. The two java processes from before are still there, plus we have two new ones from this new repl.

gaelrech avatar Jul 04 '25 15:07 gaelrech

Hi! Thanks for the report.

For clarity. Calva is not supposed to kill the repl when you disconnect from it. It's not clear what you expect in that part of the repro, but anyway, you are supposed to be able to disconnect the repl and it should keep running.

Killing the editor should kill the repl, though. I know we have unsolved problems with that on Windows, and that it sometimes glitches also on Mac and Linux. But on Mac and Linux, it should most often work.

The fact that you see two java processes is probably due to how your project is set up. A default deps.edn project should only start one java process. Maybe you are using Leiningen? This could potentially be where things go wrong, but I doubt it. Calva should only care about the process it spawns and since both your java processes still run, it seems we fail at managing this process.

You could try to close Cursor without first disconnecting the repl. It was a while since I visited the code for this, but maybe we need a connected repl in order to take it down.

You can also try this repro with a more minimal project. Calva has a command fro creating a mini Clojure project. See if you can repro this with that project.

PEZ avatar Jul 09 '25 08:07 PEZ

Hi!

Yep, its leiningen. The two processes isn't really a problem tbh, its more related to the amount of processes it ends up spawning.

For clarity. Calva is not supposed to kill the repl when you disconnect from it. It's not clear what you expect in that part of the repro, but anyway, you are supposed to be able to disconnect the repl and it should keep running.

This I did not know. Is there a command in Calva for actually killing the REPL? Because usually when I stop the REPL, I want to kill it; since when I use the calva.jackIn command it will create a new one, and I really only care about this new one that I'm creating.

You can also try this repro with a more minimal project. Calva has a command fro creating a mini Clojure project. See if you can repro this with that project.

Project I was using for this is actually pretty small (https://github.com/gaelrech/tapp), but it does use leiningen. But like I said, the two processes isn't really a problem, the problem is continuously spawning more

You could try to close Cursor without first disconnecting the repl. It was a while since I visited the code for this, but maybe we need a connected repl in order to take it down.

I'll try this out and reply back here later.

Thanks

gaelrech avatar Jul 09 '25 14:07 gaelrech

Ok, so I tried closing cursor without disconnecting the REPL, but results are the same

gaelrech avatar Jul 09 '25 15:07 gaelrech

For clarity. Calva is not supposed to kill the repl when you disconnect from it. It's not clear what you expect in that part of the repro, but anyway, you are supposed to be able to disconnect the repl and it should keep running.

Following through on this: I took a look into other commands and saw that there is the calva.jackOut; this one, indeed, seems to kill the REPL processes, so I probably should have been using this one.

So the problem here is really about when Cursor/Vscode is shutdown and there does not seem to have a hook that triggers any existing leiningen processes to be killed (clojure-lsp processes are killed correctly in such cases, for reference).

gaelrech avatar Jul 09 '25 17:07 gaelrech

Killing the editor should kill the repl, though.

I just want to clarify here that this is specifically about when the jack-in command was used to create the repl. If the repl was started outside of VS Code (and maybe inside VS Code but manually at a Terminal - though I'm not sure about this), killing VS Code should not (and does not, for me at least), kill the repl.

bpringe avatar Jul 12 '25 17:07 bpringe

I just want to clarify here that this is specifically about when the jack-in command was used to create the repl. If the repl was started outside of VS Code (and maybe inside VS Code but manually at a Terminal - though I'm not sure about this), killing VS Code should not (and does not, for me at least), kill the repl.

Yes, absolutely. It's about killing the processes spawned by Calva, not killing any REPL that might be running somewhere else.

gaelrech avatar Jul 15 '25 12:07 gaelrech

I wonder if it could be Cursor specific or something else specific to your environment, @gaelrech. I can't reproduce it.

PEZ avatar Jul 15 '25 14:07 PEZ

+1 On this, just killed like 40 instances of Java running on my Mac it has been happening more recurrently

breno12321 avatar Nov 04 '25 16:11 breno12321