lib/httpx/resolver/native.rb in httpx-0.22.2 vs lib/httpx/resolver/native.rb in httpx-0.22.3

- old
+ new

@@ -19,26 +19,12 @@ nameserver: nil, **Resolv::DNS::Config.default_config_hash, packet_size: 512, timeouts: Resolver::RESOLVE_TIMEOUT, } - end + end.freeze - # nameservers for ipv6 are misconfigured in certain systems; - # this can use an unexpected endless loop - # https://gitlab.com/honeyryderchuck/httpx/issues/56 - DEFAULTS[:nameserver].select! do |nameserver| - begin - IPAddr.new(nameserver) - true - rescue IPAddr::InvalidAddressError - false - end - end if DEFAULTS[:nameserver] - - DEFAULTS.freeze - DNS_PORT = 53 def_delegator :@connections, :empty? attr_reader :state @@ -213,19 +199,28 @@ ex = NativeResolveError.new(connection, connection.origin.host, e.message) ex.set_backtrace(e.backtrace) raise ex end - if addresses.nil? || addresses.empty? + if addresses.nil? + # Indicates no such domain was found. hostname, connection = @queries.first @queries.delete(hostname) @timeouts.delete(hostname) unless @queries.value?(connection) @connections.delete(connection) raise NativeResolveError.new(connection, connection.origin.host) end + elsif addresses.empty? + # no address found, eliminate candidates + _, connection = @queries.first + candidates = @queries.select { |_, conn| connection == conn }.keys + @queries.delete_if { |hs, _| candidates.include?(hs) } + @timeouts.delete_if { |hs, _| candidates.include?(hs) } + @connections.delete(connection) + raise NativeResolveError.new(connection, connection.origin.host) else address = addresses.first name = address["name"] connection = @queries.delete(name) @@ -307,14 +302,11 @@ def build_socket return if @io ip, port = @nameserver[@ns_index] port ||= DNS_PORT - uri = URI::Generic.build(scheme: "udp", port: port) - uri.hostname = ip - type = IO.registry(uri.scheme) - log { "resolver: server: #{uri}..." } - @io = type.new(uri, [IPAddr.new(ip)], @options) + log { "resolver: server: #{ip}:#{port}..." } + @io = UDP.new(ip, port, @options) end def transition(nextstate) case nextstate when :idle