Skip to content

EADDRINUSE when binding TCP socket with globally disabled IPv6 #4976

@badboy

Description

@badboy

Environment

Provide at least:

  • jruby 9.1.15.0 (2.3.3) 2017-12-07 929fde8 OpenJDK 64-Bit Server VM 25.144-b01 on 1.8.0_144-b01 +jit [linux-x86_64]
  • Linux xyz 4.14.12-1-ARCH #1 SMP PREEMPT Fri Jan 5 18:19:34 UTC 2018 x86_64 GNU/Linux

Other relevant info you may wish to add:

  • Discovered on Travis CI as well: Travis Build
  • IPv6 globally disabled on the system: sysctl net.ipv6.conf.all.disable_ipv6=1

Expected Behavior

Running the following code snippet:

ruby -rsocket -e 's=Socket.new(Socket::AF_INET6, Socket::SOCK_STREAM, 0);sa = Socket.pack_sockaddr_in(9090,"::1"); s.bind(sa)'

Long form:

s=Socket.new(Socket::AF_INET6, Socket::SOCK_STREAM, 0);
sa = Socket.pack_sockaddr_in(9090,"::1");
s.bind(sa)

IPv6 is globally disabled on the system: sysctl net.ipv6.conf.all.disable_ipv6=1

When running the code with MRI (2.5 or 2.4, probably even before that as well) it throws Errno::EADDRNOTAVAIL:

Traceback (most recent call last):
	1: from -e:1:in `<main>'
-e:1:in `bind': Cannot assign requested address - bind(2) for [::1]:9090 (Errno::EADDRNOTAVAIL)

I expect a similar meaningful exception when running with JRuby

Actual Behavior

When run with JRuby it throws Errno::EADDRINUSE with message including "Protocol family unavailable":

Errno::EADDRINUSE: Address already in use - bind(2) - Protocol family unavailable
    bind at org/jruby/ext/socket/RubySocket.java:237
  <main> at -e:1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions