lib/httpx/resolver/native.rb in httpx-0.6.3 vs lib/httpx/resolver/native.rb in httpx-0.6.4
- old
+ new
@@ -12,10 +12,11 @@
RECORD_TYPES = {
"A" => Resolv::DNS::Resource::IN::A,
"AAAA" => Resolv::DNS::Resource::IN::AAAA,
}.freeze
+ # :nocov:
DEFAULTS = if RUBY_VERSION < "2.2"
{
**Resolv::DNS::Config.default_config_hash,
packet_size: 512,
timeouts: RESOLVE_TIMEOUT,
@@ -40,10 +41,11 @@
true
rescue IPAddr::InvalidAddressError
false
end
end if DEFAULTS[:nameserver]
+ # :nocov:
DNS_PORT = 53
def_delegator :@connections, :empty?
@@ -91,11 +93,13 @@
rescue Errno::EHOSTUNREACH,
NativeResolveError => e
@ns_index += 1
if @ns_index < @nameserver.size
log(label: "resolver: ") do
+ # :nocov:
"failed resolving on nameserver #{@nameserver[@ns_index - 1]} (#{e.message})"
+ # :nocov:
end
transition(:idle)
else
if e.respond_to?(:connection) &&
e.respond_to?(:host)
@@ -130,10 +134,12 @@
resolve
end
end
def timeout
+ return if @connections.empty?
+
@start_timeout = Process.clock_gettime(Process::CLOCK_MONOTONIC)
hosts = @queries.keys
@timeouts.values_at(*hosts).reject(&:empty?).map(&:first).min
end
@@ -164,10 +170,12 @@
@timeouts.delete(host)
raise NativeResolveError.new(connection, host)
else
connections << connection
log(label: "resolver: ") do
+ # :nocov:
"timeout after #{prev_timeout}s, retry(#{timeouts.first}) #{host}..."
+ # :nocov:
end
end
end
@queries = queries
connections.each { |ch| resolve(ch) }