ruby / ruby/resolv

`resolv.conf` on macOS sometimes has interface suffix which breaks `resolve.rb`.

Open
#35 13 comments 0 reactions 1 assignee View on GitHub

@ioquatix is already working on this.

Since Apr 25, 2023.

Dominant language
Ruby
Stars
56
Forks
41
Avg merge
2h 38m
Merged PRs (30d)
7

Description

@ioquatix I just ran into this the other day and tried to run Resolv.getaddress on bin/rails c within the dev same environment as @trevorturk.

Loading development environment (Rails 7.0.4.3)
irb(main):001:0> Resolv.getaddress "google.com"
=> "74.125.136.100"

I can also help with repros if needed.

I put a binding.irb in the resolv.rb exception site and got this:

irb(#<Resolv::DNS::Requester::UnconnectedUDP:0x000000010685e970>):004:0> Addrinfo.ip(host).ip_address
/Users/olivierlacan/.rbenv/versions/3.2.2/lib/ruby/3.2.0/resolv.rb:4:in `ip': getaddrinfo: nodename nor servname provided, or not known (SocketError)
	from /Users/olivierlacan/.rbenv/versions/3.2.2/lib/ruby/3.2.0/resolv.rb:4:in `sender'
	from <internal:prelude>:5:in `irb'
	from 3.2.2/lib/ruby/3.2.0/resolv.rb:770:in `sender'
	from 3.2.2/lib/ruby/3.2.0/resolv.rb:527:in `block in fetch_resource'
	from 3.2.2/lib/ruby/3.2.0/resolv.rb:1126:in `block (3 levels) in resolv'
	from 3.2.2/lib/ruby/3.2.0/resolv.rb:1124:in `each'
	from 3.2.2/lib/ruby/3.2.0/resolv.rb:1124:in `block (2 levels) in resolv'
	from 3.2.2/lib/ruby/3.2.0/resolv.rb:1123:in `each'
	from 3.2.2/lib/ruby/3.2.0/resolv.rb:1123:in `block in resolv'
	from 3.2.2/lib/ruby/3.2.0/resolv.rb:1121:in `each'
	from 3.2.2/lib/ruby/3.2.0/resolv.rb:1121:in `resolv'
	from 3.2.2/lib/ruby/3.2.0/resolv.rb:521:in `fetch_resource'
	from 3.2.2/lib/ruby/3.2.0/resolv.rb:507:in `each_resource'
	from 3.2.2/lib/ruby/3.2.0/resolv.rb:402:in `each_address'
	from 3.2.2/lib/ruby/3.2.0/resolv.rb:116:in `block in each_address'
	from 3.2.2/lib/ruby/3.2.0/resolv.rb:115:in `each'
	... 30 levels...
irb(#<Resolv::DNS::Requester::UnconnectedUDP:0x000000010685e970>):005:0> host
=> "fe80::887:c7ff:fe62:d64%en0"

I have a feeling something about this %en0 (network interface?!) in the ipv6 DNS hostname is not happy. Removing it works fine.

Addrinfo.ip("fe80::887:c7ff:fe62:d64").ip_address
=> "fe80::887:c7ff:fe62:d64"

Edit: I can also confirm that this %en0 seemingly gets added when I'm tethering to an AT&T device from macOS since it is listed as such in resolv.conf:

cat /etc/resolv.conf
#
# macOS Notice
#
# This file is not consulted for DNS hostname resolution, address
# resolution, or the DNS query routing mechanism used by most
# processes on this system.
#
# To view the DNS configuration used by this system, use:
#   scutil --dns
#
# SEE ALSO
#   dns-sd(1), scutil(8)
#
# This file is automatically generated.
#
nameserver fe80::887:c7ff:fe62:d64%en0
nameserver 172.20.10.1

But this isn't shown in the macOS networking settings if you look at DNS servers:

image

AFAIK en0 in macOS parlance is an identifier for Wi-Fi network interface as this shows:

$ networksetup -listallhardwareports | grep -C 2 en0

Hardware Port: Wi-Fi
Device: en0
Ethernet Address: f0:2f:5b:01:23:b8

It seems like Resolv is choking on this identifier when it likely should be entirely ignored. Might have to file a Ruby bug report for this.

Originally posted by @olivierlacan in https://github.com/socketry/async-http/issues/107#issuecomment-1522043280

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.