Skip to content

Commit

Permalink
Strip device suffix before resolving hostname. (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix authored Jun 7, 2023
1 parent 278bb74 commit 3102d41
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/async/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ def kernel_sleep(duration = nil)

# @asynchronous May be non-blocking..
def address_resolve(hostname)
# On some platforms, hostnames may contain a device-specific suffix (e.g. %en0). We need to strip this before resolving.
# See <https://github.com/socketry/async/issues/180> for more details.
hostname = hostname.split("%", 2).first
::Resolv.getaddresses(hostname)
end

Expand Down
18 changes: 18 additions & 0 deletions test/async/scheduler/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,23 @@

expect(addresses).not.to be(:empty?)
end

it "can resolve ipv4 addresses" do
address = Addrinfo.getaddrinfo("127.0.0.1", "80").first

expect(address.ipv4?).to be == true
end

it "can resolve ipv6 addresses" do
address = Addrinfo.getaddrinfo("::1", "80").first

expect(address.ipv6?).to be == true
end

it "can resolve ipv6 addresses with device suffix" do
address = Addrinfo.getaddrinfo("::1%lo0", "80").first

expect(address.ipv6?).to be == true
end
end
end

0 comments on commit 3102d41

Please sign in to comment.