lib/httpx/resolver/native.rb in httpx-0.18.6 vs lib/httpx/resolver/native.rb in httpx-0.18.7
- old
+ new
@@ -48,11 +48,11 @@
def_delegator :@connections, :empty?
attr_reader :state
def initialize(options)
- @options = Options.new(options)
+ @options = HTTPX::Options.new(options)
@ns_index = 0
@resolver_options = DEFAULTS.merge(@options.resolver_options)
@nameserver = @resolver_options[:nameserver]
@_timeouts = Array(@resolver_options[:timeouts])
@timeouts = Hash.new { |timeouts, host| timeouts[host] = @_timeouts.dup }
@@ -198,10 +198,11 @@
addresses = Resolver.decode_dns_answer(buffer)
rescue Resolv::DNS::DecodeError => e
hostname, connection = @queries.first
if @_record_types[hostname].empty?
@queries.delete(hostname)
+ @timeouts.delete(hostname)
@connections.delete(connection)
ex = NativeResolveError.new(connection, hostname, e.message)
ex.set_backtrace(e.backtrace)
raise ex
end
@@ -211,10 +212,11 @@
hostname, connection = @queries.first
@_record_types[hostname].shift
if @_record_types[hostname].empty?
@queries.delete(hostname)
@_record_types.delete(hostname)
+ @timeouts.delete(hostname)
@connections.delete(connection)
raise NativeResolveError.new(connection, hostname)
end
else
@@ -234,16 +236,21 @@
address["name"] = name
connection = @queries.delete(name)
end
if address.key?("alias") # CNAME
- if early_resolve(connection, hostname: address["alias"])
+ # clean up intermediate queries
+ @timeouts.delete(address["name"]) unless connection.origin.host == address["name"]
+
+ if catch(:coalesced) { early_resolve(connection, hostname: address["alias"]) }
+ @timeouts.delete(connection.origin.host)
@connections.delete(connection)
else
resolve(connection, address["alias"])
return
end
else
+ @timeouts.delete(connection.origin.host)
@connections.delete(connection)
Resolver.cached_lookup_set(connection.origin.host, addresses) if @resolver_options[:cache]
emit_addresses(connection, addresses.map { |addr| addr["data"] })
end
end