gethostbyname "localhost" has no ipv6 address #4333

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


None yet

2 participants



  • jruby (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]
  • 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", ""]

Actual Behavior

jruby- will provide

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

Please make gethostbyname compatible with the recent mri ruby.

olleolleolle commented Dec 1, 2016 edited

Link to current implementation: org/jruby/ext/socket/

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?


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