gethostbyname "localhost" has no ipv6 address #4333

Open
andrew-aladev opened this Issue Nov 23, 2016 · 2 comments

Projects

None yet

2 participants

@andrew-aladev

Environment

  • jruby 9.1.6.0 (2.3.1) 2016-11-09 0150a76 OpenJDK 64-Bit Server VM 25.101-b13 on 1.8.0_101-b13 +jit [linux-x86_64]
  • JRUBY_OPTS="-J-Djava.net.preferIPv4Stack=false"
  • Installed or activated gems: puma-3.6.2-java

Puma uses TCPSocket.gethostbyname to receive a list of localhost addresses. So this issue is important for puma.

require "socket"
TCPSocket.gethostbyname "localhost"

Expected Behavior

ruby-2.3.1 will provide:

["localhost", [], 10, "::1", "127.0.0.1"]

Actual Behavior

jruby-9.1.6.0 will provide

["127.0.0.1", [], 2, "127.0.0.1"]

Please make gethostbyname compatible with the recent mri ruby.

@olleolleolle
Contributor
olleolleolle commented Dec 1, 2016 edited

Link to current implementation: org/jruby/ext/socket/RubyTCPSocket.java

In MRI trunk:

Here was a comment that taught me a thing:

 * Note that it is not guaranteed to be able to convert to IP address using gethostbyname, getaddrinfo, etc.
 * If you need local IP address, use Socket.ip_address_list.

Workaround?: Trying it, I noted that Socket.ip_address_list produces Addrinfo objects. Can those be used by puma's localhost_addresses to synthesize that list?

@andrew-aladev

Sure. This solution is ok. I will create an issue for puma.

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