technomancy / swank-clojure

Swank/slime support for clojure
Eclipse Public License 1.0
412 stars 83 forks source link

clojure-jack-in : error in process filter: open-network-stream: make client process failed: Connection refused #68

Closed ashee closed 12 years ago

ashee commented 12 years ago

I think I found a bug in clojure-jack-in. leiningen.jack-in/jack-in passes "localhost" to swank.swank/start-server which ultimately calls java.net.InetAddress/getByName("localhost") which does not return the loopback interface. But slime-connect expects to connect on the loopback. I changed the call to java.net.InetAddress/getByName(nil) and it seems to work now.

Here's the patch

From 95d561aa5cd1a30b8aba4a95a7675bbf2652627d Mon Sep 17 00:00:00 2001 From: Amitava Shee amitava.shee@gmail.com Date: Tue, 11 Oct 2011 09:25:40 -0400 Subject: [PATCH] fixed clojure-jack-in issue due to InetAddress.getByName not returning loopback


src/swank/util/net/sockets.clj | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/src/swank/util/net/sockets.clj b/src/swank/util/net/sockets.clj index 1c45ff1..af31b21 100644 --- a/src/swank/util/net/sockets.clj +++ b/src/swank/util/net/sockets.clj @@ -24,7 +24,9 @@ (when-let [host (options :host)] (if (instance? InetAddress host) host

ashee commented 12 years ago

Here's a log of error messages in emacs

M-x: clojure-jack-in

swank ;;; Bootstrapping bundled version of SLIME; please wait...

(when (not (featurep 'slime-cdf283b4)) (if (file-readable-p "/Users/amitava/.emacs.d/swank/slime-cdf283b4.elc") (load-file "/Users/amitava/.emacs.d/swank/slime-cdf283b4.elc") (byte-compile-file "/Users/amitava/.emacs.d/swank/slime-cdf283b4.el" t))) (when (not (featurep 'slime-repl-79b38c83)) (if (file-readable-p "/Users/amitava/.emacs.d/swank/slime-repl-79b38c83.elc") (load-file "/Users/amitava/.emacs.d/swank/slime-repl-79b38c83.elc") (byte-compile-file "/Users/amitava/.emacs.d/swank/slime-repl-79b38c83.el" t))) (sleep-for 0.1) (run-hooks 'slime-load-hook) ; on port 65280 ;;; proceed to jack in

Messages For information about GNU Emacs and the GNU system, type C-h C-a. Scan error: "Containing expression ends prematurely", 1107, 1107 Saving file /Users/amitava/MyCode/clj/foo/src/foo/core.clj... Wrote /Users/amitava/MyCode/clj/foo/src/foo/core.clj Starting swank server... Loading /Users/amitava/.emacs.d/swank/slime-cdf283b4.elc...done Loading /Users/amitava/.emacs.d/swank/slime-repl-79b38c83.elc...done Connecting to Swank on port 65280.. [2 times] error in process filter: open-network-stream: make client process failed: Connection refused, :name, SLIME Lisp, :buffer, nil, :host, localhost, :service, 65280, :nowait, nil error in process filter: make client process failed: Connection refused, :name, SLIME Lisp, :buffer, nil, :host, localhost, :service, 65280, :nowait, nil

slime-connects succeeds when I explicitly pass my network interface and not the loopback interface

M-x slime-connect RET Host: 10.17.8.26 RET Port: 65280 Connecting to Swank on port 65280.. [2 times] Connected. Amitava, this could be the start of a beautiful program.

Notice how InetAddress/getByName behaves user=> (import '[java.net InetAddress]) java.net.InetAddress user=> (InetAddress/getByName "localhost")

<Inet4Address localhost/10.17.8.26>

10.17.8.26, not 127.0.0.1

technomancy commented 12 years ago

This is quite strange; I've never heard of InetAddress/getByName failing in this way with "localhost". It seems more likely your machine is misconfigured if you are seeing this behaviour. Does "ping localhost" act properly for you? Perhaps it's an IPv6 issue?

ashee commented 12 years ago

I was surprised as well but the javadocs confirms this behavior. Here's some info for my host

localhost:~ amitava$ ping localhost PING localhost (127.0.0.1): 56 data bytes 64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.045 ms 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.090 ms 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.077 ms ^C --- localhost ping statistics --- 3 packets transmitted, 3 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 0.045/0.071/0.090/0.019 ms

localhost:~ amitava$ clj Clojure 1.3.0 user=> (import '[java.net InetAddress]) java.net.InetAddress user=> (InetAddress/getByName "localhost")

<Inet4Address localhost/10.21.120.148>

user=>

localhost:~ amitava$ cat /etc/hosts

Host Database

#

localhost is used to configure the loopback interface

when the system is booting. Do not change this entry.

127.0.0.1 localhost ashee 255.255.255.255 broadcasthost ::1 localhost fe80::1%lo0 localhost

fake domains

127.0.0.1 cltp.localhost.edu 127.0.0.1 lg.localhost.edu

-Amitava

On Tue, Oct 11, 2011 at 2:18 PM, Phil Hagelberg < reply@reply.github.com>wrote:

This is quite strange; I've never heard of InetAddress/getByName failing in this way with "localhost". It seems more likely your machine is misconfigured if you are seeing this behaviour. Does "ping localhost" act properly for you? Perhaps it's an IPv6 issue?

Reply to this email directly or view it on GitHub: https://github.com/technomancy/swank-clojure/issues/68#issuecomment-2369190

Amitava Shee Software Architect

There are two ways of constructing a software design. One is to make it so simple that there are obviously no deficiencies; the other is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult. -- C. A. R. Hoare The Emperor's Old Clothes, CACM February 1981

ashee commented 12 years ago

This seems to be an issue with my jvm

localhost:~ amitava$ java -version
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03-384-10M3425)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02-384, mixed mode)
localhost:~ amitava$ java -jar ~/opt/clojure/clojure-1.3.0.jar 
Clojure 1.3.0
user=> (import '[java.net InetAddress])
java.net.InetAddress
user=> (InetAddress/getByName "localhost")
#<Inet4Address localhost/192.168.1.64>

localhost:~ amitava$ uname -a
Darwin localhost 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun  7 16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386 i386

localhost:~ amitava$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.6.8
BuildVersion:   10K549

When I switched jvm to openjdk 1.7.0, it returns the loopback interface

localhost:bin amitava$ ./java -version
openjdk version "1.7.0-internal"
OpenJDK Runtime Environment (build 1.7.0-internal-b00)
OpenJDK 64-Bit Server VM (build 21.0-b09, mixed mode)
localhost:bin amitava$ ./java -jar ~/opt/clojure/clojure-1.3.0.jar 
Clojure 1.3.0
user=> (import '[java.net InetAddress])
java.net.InetAddress
user=> (InetAddress/getByName "localhost")
#<Inet4Address localhost/127.0.0.1>
ashee commented 12 years ago

I finally figured out what was wrong with my notebook setup. My hostname was set to "localhost" which is why the underlying dns lookup was returning the actual interface, not the loopback. Here's the fix

localhost:~ amitava$ sudo scutil --set HostName amitava.local
amitava:~ amitava$ scutil --get HostName
amitava.local
amitava:~ amitava$ clj
Clojure 1.3.0
user=> (import 'java.net.InetAddress)
java.net.InetAddress
user=> (InetAddress/getByName "localhost")
#<Inet4Address localhost/127.0.0.1>
user=> 
ashee commented 12 years ago

Not a bug

humasect commented 12 years ago

my machine had the same trouble. I am curious how it happened... thank you ^_^

ashee commented 12 years ago

I had made an entry in my /etc/hosts file for localhost :-)

humasect commented 12 years ago

ahh - i think my /etc/hosts was populated with some extra IPv6 stuff for localhost, like this:

::1 localhost f80::1%lo0 localhost

(or whatever these mean... they showed up when i was trying to telnet localhost (but failed) before using scutil --set HostName)