class HTTP::Timeout::Global

def connect(socket_class, host_name, *args)

def connect(socket_class, host_name, *args)
  connect_operation = lambda do |host_address|
    ::Timeout.timeout(@time_left, TimeoutError) do
      super(socket_class, host_address, *args)
    end
  end
  host_addresses = @dns_resolver.call(host_name)
  # ensure something to iterates
  trying_targets = host_addresses.empty? ? [host_name] : host_addresses
  reset_timer
  trying_iterator = trying_targets.lazy
  error = nil
  begin
    connect_operation.call(trying_iterator.next).tap do
      log_time
    end
  rescue TimeoutError => e
    error = e
    retry
  rescue ::StopIteration
    raise error
  end
end