lib/httpx/resolver/native.rb in httpx-0.10.2 vs lib/httpx/resolver/native.rb in httpx-0.11.0
- old
+ new
@@ -7,29 +7,28 @@
class Resolver::Native
extend Forwardable
include Resolver::ResolverMixin
using URIExtensions
- RESOLVE_TIMEOUT = 5
RECORD_TYPES = {
"A" => Resolv::DNS::Resource::IN::A,
"AAAA" => Resolv::DNS::Resource::IN::AAAA,
}.freeze
DEFAULTS = if RUBY_VERSION < "2.2"
{
**Resolv::DNS::Config.default_config_hash,
packet_size: 512,
- timeouts: RESOLVE_TIMEOUT,
+ timeouts: Resolver::RESOLVE_TIMEOUT,
record_types: RECORD_TYPES.keys,
}.freeze
else
{
nameserver: nil,
**Resolv::DNS::Config.default_config_hash,
packet_size: 512,
- timeouts: RESOLVE_TIMEOUT,
+ timeouts: Resolver::RESOLVE_TIMEOUT,
record_types: RECORD_TYPES.keys,
}.freeze
end
# nameservers for ipv6 are misconfigured in certain systems;
@@ -146,18 +145,23 @@
timeout = (@timeouts[host][0] -= loop_time)
unless timeout.negative?
queries[h] = connection
next
end
+
@timeouts[host].shift
if @timeouts[host].empty?
@timeouts.delete(host)
@connections.delete(connection)
- raise NativeResolveError.new(connection, host)
+ # 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")
+ # raise NativeResolveError.new(connection, host)
else
+ log { "resolver: timeout after #{timeout}s, retry(#{@timeouts[host].first}) #{host}..." }
connections << connection
- log { "resolver: timeout after #{prev_timeout}s, retry(#{timeouts.first}) #{host}..." }
+ queries[h] = connection
end
end
@queries = queries
connections.each { |ch| resolve(ch) }
end
@@ -277,10 +281,10 @@
build_socket
@io.connect
return unless @io.connected?
- resolve if @queries.empty?
+ resolve if @queries.empty? && !@connections.empty?
when :closed
return unless @state == :open
@io.close if @io
end