Project

General

Profile

Actions

Bug #21512

closed

Socket.tcp_with_fast_fallback('example.com', 80, '127.0.0.1') fails with unknown socket domain: ipv4 (SocketError)

Added by osyoyu (Daisuke Aritomo) 1 day ago. Updated about 10 hours ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 3.5.0dev (2025-07-13T04:37:15Z master f03cc0b514) +PRISM [x86_64-linux]
[ruby-core:122742]

Description

The following code is expected to open a socket bound to the local IPv4 interface, but raises an SocketError.

require 'socket'
Socket.tcp_with_fast_fallback('localhost', 8080, '127.0.0.1')

Expected behavior: Returns a Socket object
Actuai behavior: Causes a SocketError (unknown socket domain: ipv4)

I believe this is because Socket.tcp_with_fast_fallback is calling Addrinfo.getaddrinfo with :ipv4 / :ipv6 as its third argument, instead of Socket::AF_INET / Socket::AF_INET6.
https://github.com/ruby/ruby/blob/b2a7b7699261d2a4ef8a9d5d38d3fb9dc99c8253/ext/socket/lib/socket.rb#L707

Updated by osyoyu (Daisuke Aritomo) 1 day ago

I have opened a pull request: https://github.com/ruby/ruby/pull/13878

This bug is around from Ruby 3.4 when HEv2 was introduced.

Updated by hsbt (Hiroshi SHIBATA) about 18 hours ago

  • Status changed from Open to Assigned
  • Assignee set to shioimm (Misaki Shioi)
Actions #3

Updated by Anonymous about 10 hours ago

  • Status changed from Assigned to Closed

Applied in changeset git|b896f80598cc096c84d57b2024813e994637af3b.


[Bug #21512] Socket.tcp_with_fast_fallback: Pass proper addr family to getaddrinfo (#13878)

Socket.tcp_with_fast_fallback: Pass proper addr family to getaddrinfo

Addrinfo.getaddrinfo expects Socket::AF_INET or Socket::AF_INET6 as its
third argument (family). However Socket.tcp_with_fast_fallback was
incorrectly passing :ipv4 or :ipv6.

Repro:

require 'socket'
Socket.tcp_with_fast_fallback('example.com', 80, '127.0.0.1')

Expected behavior: Returns a Socket object
Actual: Raises unknown socket domain: ipv4 (SocketError)

Updated by shioimm (Misaki Shioi) about 10 hours ago

I merged this fix. Thank you!

Actions

Also available in: Atom PDF

Like1
Like0Like0Like0Like0