Skip to content

Ignore IPv6 nameservers to prevent Socket::ResolutionError#94

Merged
Watson1978 merged 1 commit intosocketry:mainfrom
Watson1978:reject-ipv6
Mar 22, 2026
Merged

Ignore IPv6 nameservers to prevent Socket::ResolutionError#94
Watson1978 merged 1 commit intosocketry:mainfrom
Watson1978:reject-ipv6

Conversation

@Watson1978
Copy link
Copy Markdown
Collaborator

The DNSResolver currently does not support IPv6 and initializes an IPv4 (AF_INET) UDP socket.

# Word to the wise: I don't know what I'm doing here. This was cobbled together
# as best I could with extremely limited knowledge of the DNS format. There's
# obviously a ton of stuff it doesn't support (like IPv6 and TCP).

However, modern OS environments often include IPv6 addresses in /etc/resolv.conf by default.

When the resolver attempts to send a query to an IPv6 nameserver using the IPv4 socket, it crashes with: Socket::ResolutionError: getaddrinfo: Address family for hostname not supported

This will fix following error:

$ rspec spec/dns_spec.rb

DNS
  connects to valid domains (FAILED - 1)
  fires on_resolve_failed for invalid domains (FAILED - 2)
  resolve localhost even though hosts is empty
  resolve missing localhost even though hosts entries exist

Failures:

  1) DNS connects to valid domains
     Failure/Error: @socket.send request_message, 0, @nameservers.first, DNS_PORT

     Socket::ResolutionError:
       getaddrinfo: Address family for hostname not supported
     # ./lib/cool.io/dns_resolver.rb:118:in 'UDPSocket#send'
     # ./lib/cool.io/dns_resolver.rb:118:in 'Coolio::DNSResolver#send_request'
     # ./lib/cool.io/dns_resolver.rb:86:in 'Coolio::DNSResolver#attach'
     # (eval at ./lib/cool.io/meta.rb:15):3:in 'Coolio::TCPSocket#attach'
     # ./spec/dns_spec.rb:28:in 'block (2 levels) in <top (required)>'
     # /home/watson/.rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/rspec-core-3.13.6/lib/rspec/core/example.rb:263:in 'BasicObject#instance_exec'
     # /home/watson/.rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/rspec-core-3.13.6/lib/rspec/core/example.rb:263:in 'block in RSpec::Core::Example#run'
     # /home/watson/.rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/rspec-core-3.13.6/lib/rspec/core/example.rb:511:in 'block in RSpec::Core::Example#with_around_and_singleton_context_hooks'
     # /home/watson/.rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/rspec-core-3.13.6/lib/rspec/core/example.rb:468:in 'block in RSpec::Core::Example#with_around_example_hooks'
     # /home/watson/.rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/rspec-core-3.13.6/lib/rspec/core/hooks.rb:486:in 'block in RSpec::Core::Hooks::HookCollections#run'
     # /home/watson/.rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/rspec-core-3.13.6/lib/rspec/core/hooks.rb:624:in 'RSpec::Core::Hooks::HookCollections#run_around_example_hooks_for'
     # /home/watson/.rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/rspec-core-3.13.6/lib/rspec/core/hooks.rb:486:in 'RSpec::Core::Hooks::Hoo
...

Types of Changes

  • Bug fix.

Contribution

The DNSResolver currently does not support IPv6 and initializes an IPv4 (AF_INET) UDP socket. However, modern OS environments often include IPv6 addresses in `/etc/resolv.conf` by default.

When the resolver attempts to send a query to an IPv6 nameserver using the IPv4 socket, it crashes with:
`Socket::ResolutionError: getaddrinfo: Address family for hostname not supported`
@Watson1978 Watson1978 merged commit f54c273 into socketry:main Mar 22, 2026
12 of 14 checks passed
@Watson1978 Watson1978 deleted the reject-ipv6 branch March 22, 2026 06:51
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

Successfully merging this pull request may close these issues.

1 participant