Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning relative paths for validation.xml files #14411

Closed
wants to merge 9 commits into from
Closed

Returning relative paths for validation.xml files #14411

wants to merge 9 commits into from

Conversation

DanCarlyon
Copy link

@DanCarlyon DanCarlyon commented Mar 28, 2018

Description

There is a bug in the Magento\Framework\Validator package which means that certain actions, for example saving a customer, will intermittently fail on multi-web server Magento environments which use different web roots per-web server but a single, shared cache instance. The bug is caused by Magento saving absolute paths to certain configuration files in the cache, as absolute paths will not be consistent between servers which have different web roots

With this change we now save the relative paths to Validation.xml configuration files. We recently faced an issue on a multi server setup where the paths to Magento were different.

Server Magento Root Path
Server 1 /var/www/vhosts/server1/httpdocs/
Server 2 /var/www/vhosts/server2/httpdocs/
Server 3 /var/www/vhosts/server3/httpdocs/

By saving the paths relative to the Magento root in the cache we can prepend the Magento root path to the url to return the absolute urls without changing any functionality, the only thing we are changing is what is saved in the cache.

Fixed Issues (if relevant)

N/A

Manual testing scenarios

Multi-server required with different web roots with a shared cache instance.

  1. Log into the admin
  2. Save a customer, this is when this method get's called
  3. Saving should still work correctly without any exception being thrown

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@DanCarlyon DanCarlyon added Partner: Space48 PR created by partner Space48 partner-contribution Partner: Space 48 Partner Space48 contribution and removed Partner: Space48 PR created by partner Space48 labels Apr 27, 2018
@ihor-sviziev ihor-sviziev added partners-contribution Pull Request is created by Magento Partner and removed partner-contribution labels Jun 5, 2018
@david-fuehr
Copy link
Contributor

In our multi node setup the same error occurred and for example prevented a successful checkout and customer registration.

As the method \Magento\Framwork\Validator\Factory::_initializeConfigList() determines which files should be loaded and only stores the absolute file paths (not the file contents), I would suggest to just skip caching rather than trying to sanitize file paths.

    /**
     * Init cached list of validation files
     */
    protected function _initializeConfigList()
    {
        if (!$this->_configFiles) {
            $this->_configFiles = $this->moduleReader->getConfigurationFiles('validation.xml');
        }
    }

@DanCarlyon what do you think?

@DanCarlyon
Copy link
Author

@david-fuehr Not sure if it's wise to bypass the caching 🤔 It's there for a reason. The patch in this PR works (Our production site has had it live now since March and no longer has the problem) I just need to sort the unit tests out.

@david-fuehr
Copy link
Contributor

I think both versions do the job - but allow me some thoughts on this fix:

I looked through your changes and think that the solution works good when the file names are stored in cache. It should save some execution time assembling the absolute path rather than searching the files in the module directories.
When you first determine the files and iterate over them to modify the path, you introduce some string operations and also read the file content (calling the method \Magento\Framework\Config\FileIterator::current on each element). The result is not cached and thus read again when the file list is iterated the next time, so this operation seems more expensive.

Also, in each case - cached or not, the file contents are read and merged in every request (see method \Magento\Framework\Validator\Config::_merge - inherited from parent). So for me the advantage of caching the file names and not the merged content is not clear.
When I look through the core files, the method \Magento\Framework\Module\Dir\Reader::getConfigurationFiles is called several times. I found no second occurrence, where the file paths but not the content is cached. In many cases it seems, as though the content is not cached at all.

@ishakhsuvarov
Copy link
Contributor

Hi @DanCarlyon
Unfortunately, we can not accept fixes to the 2.1-develop branch which are not yet part of 2.2 and 2.3
We are closing this PR now, please feel free to submit relevant fix to the newer versions first.

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Partner: Space 48 Partner Space48 contribution partners-contribution Pull Request is created by Magento Partner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants