Project

General

Profile

Actions

Bug #22545

open

Socket returns IPv6 addresses and Happy Eyeballs tests fail with `--disable-ipv6` builds

Bug #22545: Socket returns IPv6 addresses and Happy Eyeballs tests fail with `--disable-ipv6` builds

Added by datibbaw (Tjerk Meesters) 3 days ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:127469]

Description

Follow-up to #22538.

For --disable-ipv6 builds, the require 'socket' statement no longer raises an error since c99813a8d8.

However:

  • When the OS supports IPv6, DNS lookups still return IPv6 addresses, and
  • The Happy Eyeballs code and tests assume IPv6 support.

Reproduction

Build with ./configure --disable-ipv6 on a host with IPv6 (seen on macOS):

require 'socket'
p defined?(Socket::AF_INET6)
#=> nil
p Socket.getaddrinfo("localhost", 80, nil, :STREAM).map { _1[0] }
#=> ["AF_INET6", "AF_INET"]
p Addrinfo.getaddrinfo("localhost", 80, nil, :STREAM).map(&:afamily)
#=> [30, 2]
p Socket.getaddrinfo("localhost", 80, :INET6).map { _1[0] }
#=> ["AF_INET6", "AF_INET6"]
p Socket.ip_address_list.map(&:afamily).uniq
#=> [2, 30]
p Socket.tcp_server_sockets("localhost", 0).map { _1.local_address.inspect_sockaddr }
#=> ["[::1]:57139", "127.0.0.1:57139"]
p Socket.udp_server_sockets(0).size
#=> one socket per IPv6 interface address, plus the IPv4 ones

Socket.tcp_server_sockets(0) # never returns

Socket.tcp_server_sockets(0) loops forever. Socket#ipv6only! is a no-op because IPV6_V6ONLY is not defined, so the [::] socket is dual-stack, binding 0.0.0.0 on the same port always fails with EADDRINUSE, and tcp_server_sockets_port0 keeps retrying.

Test suite

make test-all TESTS=socket hangs at TestSocket#test_accept_loop_with_unix, because of the tcp_server_sockets(0) loop above. With the hanging tests excluded, the result is:

207 tests, 1219 assertions, 4 failures, 18 errors, 4 skips

Most of the failures are in the Happy Eyeballs tests (test_tcp_socket_* in test_socket.rb and test_initialize_* in test_tcp.rb). Their stubs use when Socket::AF_INET6 and fail with NameError, and some of them also expect IO::TimeoutError while IPv6 resolution is pending, which never happens without IPv6. The other failures are test_udp_server (ipv6_linklocal? on leaked addresses), test_ipv6_pktinfo, test_accept_loop, test_accept_loop_multi_port, test_linger and test_closed_read.

Proposed fix

https://github.com/ruby/ruby/compare/master...datibbaw:ruby:disable-ipv6-consistency

  • rsock_getaddrinfo (raddrinfo.c): when INET6 is not defined, turn PF_UNSPEC into PF_INET, and raise EAI_FAMILY for PF_INET6. No IPv6 address reaches Ruby, which also fixes the tcp_server_sockets(0) loop.
  • TCPSocket.new fast fallback (ipsocket.c): resolve only AF_INET when there is no IPv6.
  • Socket.ip_address_list (socket.c): skip AF_INET6 interface addresses.
  • tests: Happy Eyeballs stubs use a matcher that never matches without AF_INET6. Tests that use IPv4 addresses now run and check the error expected without IPv6 (Errno::ECONNREFUSED instead of IO::TimeoutError). Tests that explicitly need IPv6 (::1) are skipped.

With the patch:

  • Without IPv6: 207 tests, 0 failures, 0 errors, 16 skips without IPv6,
  • With IPv6: 213 tests, 0 failures, 0 errors, 4 skips with IPv6.

No data to display

Actions

Also available in: PDF Atom