lib/httpx/resolver/resolver.rb in httpx-0.21.1 vs lib/httpx/resolver/resolver.rb in httpx-0.22.0

- old
+ new

@@ -61,22 +61,28 @@ family == Socket::AF_INET && addresses.first.to_s != connection.origin.host.to_s log { "resolver: A response, applying resolution delay..." } @pool.after(0.05) do # double emission check - unless connection.addresses && addresses.intersect?(connection.addresses) - - connection.addresses = addresses - emit(:resolve, connection) - end + emit_resolved_connection(connection, addresses) unless connection.addresses && addresses.intersect?(connection.addresses) end else - connection.addresses = addresses - emit(:resolve, connection) + emit_resolved_connection(connection, addresses) end end private + + def emit_resolved_connection(connection, addresses) + if connection.io && connection.connecting? && @pool + new_connection = connection.clone_new_connection + @pool.init_connection(new_connection, connection.options) + connection = new_connection + end + connection.addresses = addresses + + emit(:resolve, connection) + end def early_resolve(connection, hostname: connection.origin.host) addresses = @resolver_options[:cache] && (connection.addresses || HTTPX::Resolver.nolookup_resolve(hostname)) return unless addresses