From: "datibbaw (Tjerk Meesters) via ruby-core" Date: 2026-11-13T11:24:48+00:00 Subject: [ruby-core:127469] [Ruby Bug#22545] Socket returns IPv6 addresses and Happy Eyeballs tests fail with `--disable-ipv6` builds Issue #22545 has been reported by datibbaw (Tjerk Meesters). ---------------------------------------- Bug #22545: Socket returns IPv6 addresses and Happy Eyeballs tests fail with `--disable-ipv6` builds https://bugs.ruby-lang.org/issues/22545 * Author: datibbaw (Tjerk Meesters) * Status: Open * ruby -v: master * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- 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): ```ruby 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. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/