In services::ensureDirectoryPathExists there is a while loop that checks to see if a directory exists and if it doesn't then it tries to create it for you. The directories follow the format of files/storage/atoms or files/storage/atoms_1 etc (we have been using it in conjunction with Scald).

There are two problems with this:

1, The mkdir command is prefixed with @ so any errors - like permission denied - are supressed.
2, The mkdir command isn't recursive, so if the storage directory doesn't exist - and we have experienced situations where it doesn't exist - then the mkdir never creates it as it will just try to create the atom_X directories within storage (as it's not recursive). This causes the while loop to never exit and become an infinite loop.

To recreate the issue you just need to delete/move the storage directory in files and try to use something which relies on Storage_api - for us that has been images that use storage_api. Then check top and you'll see apache2/php-fpm process max out (disclaimer: I have only used php-fpm with this).

Comments

greyrhino’s picture

StatusFileSize
new511 bytes
perignon’s picture

Thanks for bringing up this issue. I think we should be using drupal_mkdir instead of just php's mkdir so we can rely on site settings of file modes. I do realize that the existing code is using 0777 but the security conscious person in me does not like that. It should be 0755 (which is the default for drupal_mkdir).

greyrhino’s picture

StatusFileSize
new518 bytes

Hi Perignon - totally agree about 0777. Because of umask it never actually gets set as 777 but have removed and left for Drupal to decide using null as the second option for drupal_mkdir() - seems nicer that hard coding either.

New patch attached.

greyrhino’s picture

Issue summary: View changes

  • Perignon committed e6da776 on 7.x-1.x authored by greyrhino
    Issue #2407275 by greyrhino: Infinite loop if files/storage directory is...
perignon’s picture

Status: Active » Fixed

Committed to dev! Thanks for the contribution!

perignon’s picture

Issue tags: +Storage API 7.x-1.7

Tagging for release documentation

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.