lib/httpx/resolver/native.rb in httpx-0.4.0 vs lib/httpx/resolver/native.rb in httpx-0.4.1

- old
+ new

@@ -74,17 +74,26 @@ case @state when :open consume end nil - rescue Errno::EHOSTUNREACH => e + rescue Errno::EHOSTUNREACH, + NativeResolveError => e @ns_index += 1 if @ns_index < @nameserver.size + log(label: "resolver: ") do + "failed resolving on nameserver #{@nameserver[@ns_index - 1]} (#{e.message})" + end transition(:idle) else - @queries.each do |host, connection| + if e.respond_to?(:connection) && + e.respond_to?(:host) emit_resolve_error(connection, host, e) + else + @queries.each do |host, connection| + emit_resolve_error(connection, host, e) + end end end end def interests @@ -139,12 +148,11 @@ next end @timeouts[host].shift if @timeouts[host].empty? @timeouts.delete(host) - emit_resolve_error(connection, host) - return + raise NativeResolveError.new(connection, host) else connections << connection log(label: "resolver: ") do "timeout after #{prev_timeout}s, retry(#{timeouts.first}) #{host}..." end @@ -186,21 +194,21 @@ begin addresses = Resolver.decode_dns_answer(buffer) rescue Resolv::DNS::DecodeError => e hostname, connection = @queries.first if @_record_types[hostname].empty? - emit_resolve_error(connection, hostname, e) - return + ex = NativeResolveError.new(connection, hostname, e.message) + ex.set_backtrace(e.backtrace) + raise ex end end if addresses.empty? hostname, connection = @queries.first @_record_types[hostname].shift if @_record_types[hostname].empty? @_record_types.delete(hostname) - emit_resolve_error(connection, hostname) - return + raise NativeResolveError.new(connection, hostname) end else address = addresses.first connection = @queries.delete(address["name"]) return unless connection # probably a retried query for which there's an answer