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

Creating a new TCPServer on the unspecified address ( creates a ipv6 address, not ipv4 #5883

nateberkopec opened this issue Sep 19, 2019 · 3 comments


Copy link

commented Sep 19, 2019


  • jruby (2.5.3) 2019-04-09 8a269e3 Java HotSpot(TM) 64-Bit Server VM 25.65-b01 on 1.8.0_65-b17 +jit [darwin-x86_64]
  • Darwin odachi 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64 x86_64


require 'socket'
s ="", 9292)
# MRI: #<TCPServer:fd 11, AF_INET,, 9292>
# JRuby: #<TCPServer:fd 5>
# MRI: #<Addrinfo: TCP>
# JRuby: #<Addrinfo: [::]:9292>

Maybe related maybe not: do |addrinfo|
  addrinfo.ipv6_loopback? || addrinfo.ipv4_loopback? { |addrinfo| addrinfo.ip_address }.uniq
# MRI: ["", "::1"]
# JRuby: ["::1", ""]

This comment has been minimized.

Copy link

commented Sep 21, 2019

This logic pretty much just leans on the JDK to make a connection. See the FAQ here:

[] ~/projects/ruby $ jruby -rsocket -e 'p"", 9292).local_address'
#<Addrinfo: [::]:9292>

[] ~/projects/ruby $ jruby -rsocket -e 'p"", 9292).local_address'

Just to make it clear this is a JDK behavior, here's a script that uses the JDK classes directly from Ruby:

[] ~/projects/jruby $ cat blah.rb
addr ='')
ssc =
socket_address =, 9292)
puts ssc

[] ~/projects/jruby $ jruby blah.rb[/0:0:0:0:0:0:0:0:9292]

[] ~/projects/jruby $ jruby blah.rb[/]

This comment has been minimized.

Copy link

commented Sep 21, 2019

A bit more info from the docs of OpenJDK itself:

On dual stack machines, system properties are provided for setting the preferred protocol stack—IPv4 or IPv6—as well as the preferred address family types—inet4 or inet6.

IPv6 stack is preferred by default, since on a dual-stack machine IPv6 socket can talk to both IPv4 and IPv6 peers.

This setting can be changed through the<true|false> system property.

At one point we did attempt to force IPv4, but that resulted in JRuby sockets being unable, by default, to connect to IPv6 hosts.


This comment has been minimized.

Copy link

commented Sep 21, 2019

I think this is the issue where we removed the IPv4 property, because it was interfering with IPv6 operation: #1286.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.