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

error in process filter: [nREPL] Direct connection failed #1945

Closed
hanshuebner opened this issue Feb 26, 2017 · 11 comments
Closed

error in process filter: [nREPL] Direct connection failed #1945

hanshuebner opened this issue Feb 26, 2017 · 11 comments

Comments

@hanshuebner
Copy link
Contributor

M-x cider-jack-in fails to successfully connect to the leiningen subprocess in some cases. I have been seeing this issue in a long time, on various machines and with a number of cider versions. Sometimes, retrying the M-x cider-jack-in one or a few times helped. Recently, when I was annoyed by this again, I tried to figure out what the problem could be by running telnet localhost <the-port-number> and found that telnet tried to connect to ::1 (ipv6 localhost), getting a "connection refused" message. When I used telnet 127.0.0.1 <the-port-number> however, the connection was accepted. It seems that the nrepl server only listens on ipv4 (maybe by using an explicit 127.0.0.1 address to listen on), but cider uses localhost as host name to connect. Thus, it depends on the local systems' interpretation and name resolution configuration what address cider tries to connect to.

Bozhidar made the very good suggestion that the message could be improved to include information as to what connection actually failed. Something like [nREPL] could not connect to localhost:12345 would already give a hin in what direction one could investigate.

The connection between cider and the nrepl server should use the same host specification, I think. Thus, if nrepl listens on 127.0.0.1 by default, cider should also use 127.0.0.1 and not localhost to avoid mismatches caused by name resolution.

@bbatsov
Copy link
Member

bbatsov commented Feb 26, 2017

We'll definitely improve those messages. As for the nREPL's behaviour - seems to me that it listens on localhost (see https://github.com/clojure/tools.nrepl/blob/fcac1e13d6f80eb0db28773247a769c1dc9659b1/src/main/clojure/clojure/tools/nrepl/server.clj#L125).

@hanshuebner
Copy link
Contributor Author

hanshuebner commented Feb 27, 2017

The real fix is within tools.nrepl, as @bbatsov has pointed out. The trick is to bind the socket to the anylocal address :: instead of localhost, 127.0.0.1 or ::1. If done that way, the nrepl server accepts connections both to the IPv4 and IPv6 localhost address. I will try to get this changed in tools.nrepl.

https://docs.oracle.com/javase/8/docs/technotes/guides/net/ipv6_guide/

@bbatsov
Copy link
Member

bbatsov commented Feb 27, 2017

Great! Hopefully @cemerick will have time to apply your patch and issue a new release.

@hanshuebner
Copy link
Contributor Author

As a workaround, :repl-options {:host "::"} can be specified in the user's profile to override the default in tools.nrepl until it is fixed there.

bbatsov added a commit that referenced this issue Mar 4, 2017
This should make it easier for people to figure out what's going on.
@bbatsov
Copy link
Member

bbatsov commented Mar 7, 2017

As a workaround, :repl-options {:host "::"} can be specified in the user's profile to override the default in tools.nrepl until it is fixed there.

I've updated the connection messages. Maybe we should add this workaround to the global lein options in cider for the time being, as I doubt the nREPL patch would be merged any time soon.

@bbatsov
Copy link
Member

bbatsov commented Mar 8, 2017

@benedekfazekas do you know if we can pass this as a command line option to lein and boot?

@benedekfazekas
Copy link
Member

benedekfazekas commented Mar 8, 2017

should be possible, yes. with lein you can merge anything into the project map from the CLI and a quick look on boot repl options shows me:

-H, --host HOST       HOST sets the host client connects to.

so something like boot repl -H "::" should do the trick for boot.

really busy but I might have time to give this a go over the weekend

@bbatsov
Copy link
Member

bbatsov commented Mar 8, 2017

I was just looking into this myself and found what I needed. In lein you can also do lein repl :headless :host :port.

I'll likely just add those to the default commands. Seems like an overkill to add defcustoms for them.

@ryanswilson59
Copy link

@hanshuebner sorry for the noob question but how would one go about adding :repl-options {:host "::"} to their user profile

@hanshuebner
Copy link
Contributor Author

This blog post has an overview of leiningen profiles.

@saramsey
Copy link

saramsey commented Jul 3, 2020

We'll definitely improve those messages. As for the nREPL's behaviour - seems to me that it listens on localhost (see https://github.com/clojure/tools.nrepl/blob/fcac1e13d6f80eb0db28773247a769c1dc9659b1/src/main/clojure/clojure/tools/nrepl/server.clj#L125).

Thank you, this hint was super helpful.

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

No branches or pull requests

5 participants