lib/httpx/resolver/native.rb in httpx-0.21.0 vs lib/httpx/resolver/native.rb in httpx-0.21.1
- old
+ new
@@ -11,18 +11,18 @@
DEFAULTS = if RUBY_VERSION < "2.2"
{
**Resolv::DNS::Config.default_config_hash,
packet_size: 512,
timeouts: Resolver::RESOLVE_TIMEOUT,
- }.freeze
+ }
else
{
nameserver: nil,
**Resolv::DNS::Config.default_config_hash,
packet_size: 512,
timeouts: Resolver::RESOLVE_TIMEOUT,
- }.freeze
+ }
end
# nameservers for ipv6 are misconfigured in certain systems;
# this can use an unexpected endless loop
# https://gitlab.com/honeyryderchuck/httpx/issues/56
@@ -33,10 +33,12 @@
rescue IPAddr::InvalidAddressError
false
end
end if DEFAULTS[:nameserver]
+ DEFAULTS.freeze
+
DNS_PORT = 53
def_delegator :@connections, :empty?
attr_reader :state
@@ -150,25 +152,33 @@
h, connection = query
host = connection.origin.host
timeout = (@timeouts[host][0] -= loop_time)
- return unless timeout.negative?
+ return unless timeout <= 0
@timeouts[host].shift
- if @timeouts[host].empty?
+
+ if !@timeouts[host].empty?
+ log { "resolver: timeout after #{timeout}s, retry(#{@timeouts[host].first}) #{host}..." }
+ resolve(connection)
+ elsif @ns_index + 1 < @nameserver.size
+ # try on the next nameserver
+ @ns_index += 1
+ log { "resolver: failed resolving #{host} on nameserver #{@nameserver[@ns_index - 1]} (timeout error)" }
+ transition(:idle)
+ resolve(connection)
+ else
+
@timeouts.delete(host)
@queries.delete(h)
return unless @queries.empty?
@connections.delete(connection)
# This loop_time passed to the exception is bogus. Ideally we would pass the total
# resolve timeout, including from the previous retries.
raise ResolveTimeoutError.new(loop_time, "Timed out while resolving #{connection.origin.host}")
- else
- log { "resolver: timeout after #{timeout}s, retry(#{@timeouts[host].first}) #{host}..." }
- resolve(connection)
end
end
def dread(wsize = @resolver_options[:packet_size])
loop do