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

EADDRINUSE when binding TCP socket with globally disabled IPv6 #4976

Closed
badboy opened this issue Jan 15, 2018 · 4 comments
Closed

EADDRINUSE when binding TCP socket with globally disabled IPv6 #4976

badboy opened this issue Jan 15, 2018 · 4 comments

Comments

@badboy
Copy link

badboy commented Jan 15, 2018

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
@headius
Copy link
Member

headius commented Jan 25, 2018

This is fixed in 788cd5b. @badboy Maybe you can figure out a way to write a spec/test for this? I'm not sure how easy it will be to temporarily disable ipv6 for one test though. cc @eregon

@headius headius closed this as completed Jan 25, 2018
@headius headius added this to the JRuby 9.1.16.0 milestone Jan 25, 2018
@headius
Copy link
Member

headius commented Jan 25, 2018

The error message now looks like this:

Errno::EADDRNOTAVAIL: Cannot assign requested address - bind(2) for 0:0:0:0:0:0:0:1:9090

@badboy
Copy link
Author

badboy commented Jan 25, 2018

Oh cool! Thanks for fixing that.
IPv6 can be disabled using sysctl net.ipv6.conf.all.disable_ipv6=1 quite easily, but it requires root privileges. That's probably not a good approach for a single test in a larger test suite.

@eregon
Copy link
Member

eregon commented Jan 25, 2018

It sounds difficult to disable IPv6 for a specific test.
But maybe we can just test binding a IPv6 address and accept both outcomes (returns 0 or EADDRNOTAVAIL but no other error).

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

3 participants