1

I'm using vs code with calva on Ubuntu. My clojure app listens on a port and I find that if I exit vs code, it leaves a java process bound to that port which I have to locate and kill before I can start again.

Is there any calva command to stop the repl?, or better still, a way of stopping the repl automatically when I exit vs code?

Andy
  • 10,412
  • 13
  • 70
  • 95
  • 1
    Is this phenomenon exclusive for Ubuntu? cmd+shift+p and search for 'Disconnect from REPL server' Doesn't this work? – Sanghyun Kim Feb 08 '22 at 09:54
  • @SanghyunKim hmm yes I can see that command now. I notice it only appears when you are connected to a repl, so maybe that's why I didn't see it before. The effect of disconnecting is a bit odd - it doesn't actually kill the java process at the point you disconnect but reconnecting causes the previous one to be killed so that works for me! – Andy Feb 09 '22 at 18:09
  • 1
    I just tested it and you can start a REPL, then close vscode, open it again and reconnect to the same nREPL server. If you really want to stop the nREPL server you can always evaluate `(System/exit 0)` and that will cause the JVM to exit. – Denis Fuenzalida Feb 10 '22 at 03:51

2 Answers2

2

You are right to expect that the process (if started by Calva) should be owned by Calva/VS Code and that exiting VS Code should kill it. Please report this as a bug on Calva: https://github.com/BetterThanTomorrow/calva This works on MacOS (and I think on Windows too) so please report this from VS Code's help menu so that your system info gets attached.

As for how to kill the REPL. You can press Ctrl+C in the terminal where the process is started. We should add a proper command for it as well, but that's for another day. (That it gets killed when you disconnect the REPL is a also a bug, I would say.)

PEZ
  • 16,821
  • 7
  • 45
  • 66
0

From the comments I've figured out that I was really asking the wrong question. I was under the impression that the repl was "owned by" to the vs code process that started it and that not terminating it when you quit vs code was a bug, but really my understanding wasn't right.

So to solve my original problem of leaving a process bound to the port, there are 3 options:

  1. Terminate the repl using clojure (System/exit 0)
  2. Use the calva command to reconnect to the existing repl after restarting vs code
  3. Use calva to disconnect from the repl, then you have the choice of starting a new one (which automatically will kill the old one) or re-connecting later
Andy
  • 10,412
  • 13
  • 70
  • 95
  • It might be more of a VS Code issue than a Calva one. According to the author of Calva on Slack: "It could be the feature where VS Code detaches and reattaches terminal sessions when closing and reopening a workspace. There might be a setting to disable this. And maybe Calva should have a way to deal with it. To manually kill the jack-in process, press ctrl+c in the jack-in terminal." – Eugene Pakhomov Feb 11 '22 at 16:06
  • It is actually a bit strange that the jack-in terminal does not behave like the normal terminals when reloading the window. It would be pretty nice, if it did, because it hurts killing the REPL because something wants the window reloaded. – PEZ Feb 11 '22 at 16:24