Why does nREPL server shut down when idle?

Heya guys.
I REALLY don’t know where to ask this question, or how to even tag it properly. Doing the usual google / clojureverse search didn’t help much either…

Why does the nREPL server just up and disconnect after a period of inactivity?

  • just open up a project in, say, VSCode / Calva
  • jack-in to the REPL
  • get up to have lunch or some other AFK activity
  • come back to it a~and
  • it’s automatically disconnected, the server is shut down, you have to jack-in again

Why?
Is there some security / stability concern with staying connected to the REPL?
Is there a “keep alive” setting somewhere I need to configure?
Am I insane for wanting an “immutable” environment to stay how I left it, no matter for how long?

The nREPL server is happy to stay connected forever, and so is Calva.
Perhaps you connect Calva to an nREPL port on another machine, and either an SSH server or a firewall disconnects it?

Are you sure you don’t have the computer going to sleep, or something of that sort?

Don’t think that’s the problem here, it’s all on the same machine. I’m just opening a local repo, jacking-in, waiting and observing a disconnect.

Lemme recheck my power management settings

  • sleep after: never
  • hibernate after: never
  • turn off display after: 15 min.

Am I insane for wanting an “immutable” environment to stay how I left it, no matter for how long?

Absolutely not. I have sometimes had nrepl server and connections open for weeks.

Are you on Windows by any chance (“hibernate” suggests to me you are)? This could be a windows specific issue :thinking:

Yup, good catch, I am on windows, but no clue how this could be a windows issue…

What’s your setup in Windows? Do you use WSL at all?

With WSL I’ve had issues with disconnects. Are you using VSCode where it runs on Windows but nRepl runs in inside WSL for example?

Other then that, I’m not sure, could have something to do with how Calva starts the nRepl server on Windows.

You could try to start nRepl yourself with the command line, and connect to it, instead of having Calva start it for you.

I guess there could be a clue there, but how do I even find out if nrepl is using wsl in the backgroud?

Good Idea, I’ll try testing it in a bit.

I am on windows most of the time. Never had a problem with long running repl, even through suspension/hibernation. I used emacs + cider though. Fascinating. No WSL crutch.

So yeah, I tested it:

in PowerShell

> lein repl
nREPL server started on port ...
REPL-y 0.5.1, nREPL 0.8.3
Clojure 1.10.3
OpenJDK 64-Bit Server VM 17.0.1+12-39

nice, now a sanity check

user=> (+ 1 1)
2

good, now we wait…

*2 hours later* alright, let’s test this

user=> (+ 2 2)
SocketException Connection reset by peer
...
Bye for now!

:no_mouth: what is happening?!?

maybe windows networking or antivirus junk is interfering somehow; no idea. never ran into this (on multiple machines). I have no theories.

My best guess is that your network interface is for some reason getting interrupted and probably restarts. It could be drivers, it could be something else. But I doubt it has anything to do with nRepl, except perhaps for the fact that nRepl doesn’t have support for reconnecting after a disconnect.

I tested it a few more times
on 2 machines (on the same home network, 1 lan, 1 wi-fi, if that should matter at all)
both with local leiningen installs
both lasting at most a few hours, with inconsistent time spans

so, no clue here either…

what version of windows, lein, jvm, etc?

windows 10 21H2
vscode & calva both latest versions
lein 2.9.7
the versions of jdk, clojure, nrepl & repl-y you’ve already seen:

> lein repl
nREPL server started on port ...
REPL-y 0.5.1, nREPL 0.8.3
Clojure 1.10.3
OpenJDK 64-Bit Server VM 17.0.1+12-39

but if I had to take a wild guess, none of these has a history of random network issues…

Have you tried setting up a minimal lein install inside WSL? Do you see the behavior there? For example, after enabling WSL and installing Ubuntu from the Windows store, go to the Ubunto CLI and

# Get Java and the curl utility
sudo apt install default-jdk curl 

# Download lein and make it executable
curl https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein
chmod +x lein

# repl-y away!
./lein repl

(I didn’t test the above but it should be very close if not correct.)

I’m curious–is this REPL stable for you?

alright, not to be mean to the people who are trying to help me or anything…
still, since my homework is getting more and more elaborate with each suggestion, let’s take a step back and look at the big picture:
what I wanted at the end of this road was “taking my hands off the keyboard without the fear of REPL disconnecting on a whim”
with a subtext of “why the heck should jacking-in or staying connected be manual anyway?”
and now it’s coming down to erecting temples in honor of the REPL gods and sacrificing a virgin every time I need to jack-in… :expressionless:
again, I’m sorry if I sound ungrateful for your advice

You appear to be an extreme outlier since this is possible for everyone who has responded. Staying connected is not typically a manual prospect; it just works (although connection stability is dependent on the underlying protocols). jacking in is a choice since you are interacting with a running process (local or remote).

erecting temples in honor of the REPL gods and sacrificing a virgin every time I need to jack-in

Given the extreme nature of your situation, people are providing suggestions to explore possible reasons for this oddity. It’s weird.

Hi
a couple of things that might cause your issue that I can think of is 1- if you are following the tutorial and tried the Ctrl-Alt-C and used the wrong port or something. I know you say you were connected; but it may be that using the wrong port might disconnect you.
Also the temp directory as you know is used for fireup demo, and it might get cleaned up and that might cause your issue.
In my case the port is 36447 and I have to specify that in the vscode command after I choose a Generic project. This is all when you you do Ctrl+Alt+C enter to connect. I do realize your original question was about getting disconnected. Just figure if you can reconnect, it may not be as much of an issue. I did experience the same by the way, but I was fiddling with the Ctrl+Alt+C enter command. Hope it helps. Basically in order to reconnect in vscode use the Ctrl+Alt+C enter, and the command pallet opens up asking which project type you like to use, and I chose “Generic”, then it populates the Command Pallet with the word “localhost”, and you have to add the port to the end of that. I found my port in the terminal from the previous session. I assume it is the same, but I am on a Linux machine. I am not sure about Windows. Good luck.