lib/httpx/resolver/resolver.rb in httpx-1.1.5 vs lib/httpx/resolver/resolver.rb in httpx-1.2.0

- old
+ new

@@ -36,10 +36,12 @@ @options = Options.new(options) end def close; end + alias_method :terminate, :close + def closed? true end def empty? @@ -63,23 +65,32 @@ log { "resolver: A response, applying resolution delay..." } @pool.after(0.05) do unless connection.state == :closed || # double emission check (connection.addresses && addresses.intersect?(connection.addresses)) - emit_resolved_connection(connection, addresses) + emit_resolved_connection(connection, addresses, early_resolve) end end else - emit_resolved_connection(connection, addresses) + emit_resolved_connection(connection, addresses, early_resolve) end end private - def emit_resolved_connection(connection, addresses) - connection.addresses = addresses + def emit_resolved_connection(connection, addresses, early_resolve) + begin + connection.addresses = addresses - emit(:resolve, connection) + emit(:resolve, connection) + rescue StandardError => e + if early_resolve + connection.force_reset + throw(:resolve_error, e) + else + emit(:error, connection, e) + end + end end def early_resolve(connection, hostname: connection.origin.host) addresses = @resolver_options[:cache] && (connection.addresses || HTTPX::Resolver.nolookup_resolve(hostname))