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

Cannot connect to a listener on 0.0.0.0 #87

Closed
informatimago opened this issue Jul 28, 2022 · 3 comments
Closed

Cannot connect to a listener on 0.0.0.0 #87

informatimago opened this issue Jul 28, 2022 · 3 comments

Comments

@informatimago
Copy link

Related to #75 but here, characterised as a bug.

This is in the context of IPv6, with both IPv6 and IPv4 interfaces.

Notably, localhost has a A and an AAAA records!

17:48[pjb@despina org.xquartz:0 ~ 17Gi]$ ping -c 3 localhost
PING localhost (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.053 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.046 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.054 ms

--- localhost ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.046/0.051/0.054/0.004 ms

17:48[pjb@despina org.xquartz:0 ~ 17Gi]$ ping6 -c 3 localhost
PING6(56=40+8+8 bytes) ::1 --> ::1
16 bytes from ::1, icmp_seq=0 hlim=64 time=0.088 ms
16 bytes from ::1, icmp_seq=1 hlim=64 time=0.074 ms
16 bytes from ::1, icmp_seq=2 hlim=64 time=0.073 ms

--- localhost ping6 statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/std-dev = 0.073/0.078/0.088/0.007 ms

Listening to localhost and connecting to localhost works:

(usocket:with-socket-listener (listen  "localhost"   9999 :element-type '(unsigned-byte 8) :reuseaddress t :backlog 1)
  (usocket:with-client-socket (client client-stream  "localhost" 9999 :element-type '(unsigned-byte 8))
    (usocket:with-server-socket (server (usocket:socket-accept listen))
      (write-byte 42  client-stream)
      (force-output client-stream)
      (read-byte  (usocket:socket server)))))

42

But listening on all the IPv4 addresses, and connecting to localhost does not work:

(usocket:with-socket-listener (listen  "0.0.0.0"   9999 :element-type '(unsigned-byte 8) :reuseaddress t :backlog 1)
  (usocket:with-client-socket (client client-stream  "localhost" 9999 :element-type '(unsigned-byte 8))
    (usocket:with-server-socket (server (usocket:socket-accept listen))
      (write-byte 42  client-stream)
      (force-output client-stream)
      (read-byte  (usocket:socket server)))))

> Debug: Error #<usocket:connection-refused-error #x3020051CEBCD>
> While executing: (:internal swank::invoke-default-debugger), in process worker(470).
> Type :POP to abort, :R for a list of available restarts.
> Type :? for other options.

$ macosx-netstat-tnpl |grep 9999
tcp4       0      0  *.9999                 *.*                    LISTEN

That's because as mentionned in #75, usocket:socket-connect only tries IPv6 and not both IPv6 and IPv4 addresses. Cf. patch provided in #75.

@binghe
Copy link
Member

binghe commented Jul 28, 2022

Hi Pascal J. Bourguignon,

I'm sorry that I overlooked your code provided in #75. Now I have committed your version (for Clozure CL since its IPv6 support), and added the above two tests into the test suite. I'm also on macOS, now it seems worked:

? (usocket:with-socket-listener (listen  "localhost"   9999 :element-type '(unsigned-byte 8) :reuseaddress t :backlog 1)
  (usocket:with-client-socket (client client-stream  "localhost" 9999 :element-type '(unsigned-byte 8))
    (usocket:with-server-socket (server (usocket:socket-accept listen))
      (write-byte 42  client-stream)
      (force-output client-stream)
      (read-byte  (usocket:socket server)))))
42
? (usocket:with-socket-listener (listen  "0.0.0.0"   9999 :element-type '(unsigned-byte 8) :reuseaddress t :backlog 1)
  (usocket:with-client-socket (client client-stream  "localhost" 9999 :element-type '(unsigned-byte 8))
    (usocket:with-server-socket (server (usocket:socket-accept listen))
      (write-byte 42  client-stream)
      (force-output client-stream)
      (read-byte  (usocket:socket server)))))
42

Thanks again for your patch.

Regards,

Chun Tian

@binghe binghe closed this as completed Jul 28, 2022
@binghe
Copy link
Member

binghe commented Jul 28, 2022

And I will test and adapt your algorithm also on other Lisp platforms (which supports IPv6, especially LispWorks and SBCL) to see if they suffer from the issue.

@informatimago
Copy link
Author

Thank you.

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

No branches or pull requests

2 participants