colinmollenhour / Cm_Cache_Backend_File

Much improved replacement for Zend_Cache_Backend_File - works great with Magento!
144 stars 35 forks source link

Magento Application becoming unresponsive - suspect umask race type issue #20

Closed Flipmediaco closed 10 years ago

Flipmediaco commented 10 years ago

Hi

On occasions we have found the Magento application to be failing, after investigation we found the following entries in the system.log:-

2014-06-30T08:47:16+00:00 DEBUG (7): file_get_contents(/var/www/vhosts/domain/httpdocs/var/cache//cm-tags/cm---dbc_BLOCK_HTML_RSS_ORDER_NEW) [function.file-get-contents]: failed to open stream: No such file or directory/var/www/vhosts/domain/httpdocs/.modman/Cm_Cache_Backend_File/File.php 2014-06-30T08:47:16+00:00 DEBUG (7): file_get_contents(/var/www/vhosts/domain/httpdocs/var/cache//cm-tags/cm---dbc_BLOCK_HTML_RSS_CATALOG_NOTIFYSTOCK) [function.file-get-contents]: failed to open stream: No such file or directory/var/www/vhosts/domain/httpdocs/.modman/Cm_Cache_Backend_File/File.php 2014-06-30T08:47:16+00:00 DEBUG (7): file_get_contents(/var/www/vhosts/domain/httpdocs/var/cache//cm-tags/cm---dbc_BLOCK_HTML_RSS_ORDER_NEW) [function.file-get-contents]: failed to open stream: No such file or directory/var/www/vhosts/domain/httpdocs/.modman/Cm_Cache_Backend_File/File.php 2014-06-30T08:47:16+00:00 DEBUG (7): file_get_contents(/var/www/vhosts/domain/httpdocs/var/cache//cm-tags/cm---dbc_BLOCK_HTML_RSS_CATALOG_NOTIFYSTOCK) [function.file-get-contents]: failed to open stream: No such file or directory/var/www/vhosts/domain/httpdocs/.modman/Cm_Cache_Backend_File/File.php 2014-06-30T08:47:16+00:00 DEBUG (7): file_get_contents(/var/www/vhosts/domain/httpdocs/var/cache//cm-tags/cm---dbc_BLOCK_HTML_RSS_ORDER_NEW) [function.file-get-contents]: failed to open stream: No such file or directory/var/www/vhosts/domain/httpdocs/.modman/Cm_Cache_Backend_File/File.php 2014-06-30T08:47:16+00:00 DEBUG (7): file_get_contents(/var/www/vhosts/domain/httpdocs/var/cache//cm-tags/cm---dbc_BLOCK_HTML_RSS_CATALOG_NOTIFYSTOCK) [function.file-get-contents]: failed to open stream: No such file or directory/var/www/vhosts/domain/httpdocs/.modman/Cm_Cache_Backend_File/File.php 2014-06-30T08:47:16+00:00 DEBUG (7): file_get_contents(/var/www/vhosts/domain/httpdocs/var/cache//cm-tags/cm---dbc_BLOCK_HTML_RSS_ORDER_NEW) [function.file-get-contents]: failed to open stream: /var/www/vhosts/domain/httpdocs/.modman/Cm_Cache_Backend_File/File.php

Our cache directory looked like this at the time of error:-

drwxrwx--- 2 apache apache 4096 Jun 30 10:48 cm--c6 drwxrwx--- 2 apache apache 4096 Jun 30 10:48 cm--c9 drwxrwx--- 2 apache apache 4096 Jun 30 10:48 cm--cd drwxr-xr-x 2 root root 4096 Jun 30 10:55 cm--cf drwxrwx--- 2 apache apache 4096 Jun 30 10:48 cm--d0 drwxrwx--- 2 apache apache 4096 Jun 30 10:48 cm--d6 drwxr-xr-x 2 root root 4096 Jun 30 10:49 cm--dc drwxr-xr-x 2 root root 4096 Jun 30 10:55 cm--dd drwxrwx--- 2 apache apache 4096 Jun 30 10:48 cm--de drwxrwx--- 2 apache apache 4096 Jun 30 10:48 cm--e0 drwxrwx--- 2 apache apache 4096 Jun 30 10:48 cm--e4 drwxrwx--- 2 apache apache 4096 Jun 30 10:48 cm--e7

Whilst we have umask(0007) set in index.php we did the following to ensure the cache remains readable to all of the Magento applications incarnations...

In the first instance we made sure cron.php and any instance of the app were run by apache, using the apache cron tab etc, that eliminated the root entires and then we called umask(0007) in Mage.php to ensure all have the correct umask, as Mage.php is always called for all incarnations of the Magento application.

As of now all entries in our cache directory are owned by apache and have the same permissions and we are waiting for another instance of the race type condition that caused some parts of the application to become unresponsive. Hopefully this has fixed this problem!

I am posting this for any other insights users and developers may have regarding similar issues.

Thanks Laurie

colinmollenhour commented 10 years ago

Yes this does appear to be a file ownership/permission issue. Feel free to submit a pull request with an update to the README with better setup instructions. The "use_chmod" feature is useful for those that don't understand file permissions well enough to set it up correctly so this should probably be made more obvious in the README as well.

Flipmediaco commented 10 years ago

Hi Colin

Thanks for your guidance but on review of your README.mb file I believe you are missing the fact that not all Magento actions use index.php (where you suggest setting umask(0007)).

Both indexer.php and cron.php do not use the index.php and as such any cache files generated in either the manual index or cron.php could potentially result in files with incorrect file permissions.

Additionally with the cron being run as root (most often the case) this issue can be made worse with cache files being created by root with a permission outside of the Apache scope for removal.

Setting the umask in Mage.php will ensure all cache files are always created with the correct permissions.

colinmollenhour commented 10 years ago

Ahh, I did forget to mention cron.php and indexer.php in the README.. Thanks for pointing that out. Using Mage.php definitely makes sense, I will update the README.