Problem/Motivation
MTimeProtectedFastFileStorage is implemented in such a way that if the destination file has already been writen by another process it will crash.
This how it works:
[1] Dump data into a temporary file.
[2] Set the temporary file permissions to 0444
[3] Move (php's rename) the file to the final destination
On a concurrent scenario another process might have writen the destination file before [3] executes, and because the destination file has 0444 permissions, rename() will fail:
Uncaught PHP Exception Symfony\Component\Debug\Exception\ContextErrorException: "Warning: rename(sites/default/files/php/twig/.8ce54ded2f,sites/default/files/php/twig/424c69bc_views-view.html.twig_bebe34fa92/e2dd91915d.php): Access is denied. (code: 5)" at \core\lib\Drupal\Component\PhpStorage\MTimeProtectedFastFileStorage.php line 98
Proposed resolution
We need something better than php's rename... symfony has a Filesystem component, but I found it not suited for this particular task.
Implement a custom Filesystem component in Drupal to have better tools to deal with the file system.
Remaining tasks
User interface changes
None.
API changes
New API.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | core-concurrent-phpstorage-2700019-25.patch | 5.3 KB | smustgrave |
Comments
Comment #2
david_garcia commentedComment #3
david_garcia commentedThere are actualy two bugs being solved in the patch... TwigPhpStorageCache will store the cache data even if the storage fails to do it's job :(
Comment #11
mxr576Comment #13
ghost of drupal pastWell, that's surprising.
https://www.drupal.org/project/drupal/issues/2547827#comment-10213679
I will dig more. This was supposedly solved before 8.0 came out, something apparently went sideways.
Comment #14
smustgrave commentedWonder if anyone found a fix for this? We have been getting TONS of these type of warnings in the logs
Warning: rename(sites/default/files/php/twig/.JLuI-UXp6G9u2U8U1AHnDATZ71w,sites/default/files/php/twig/615f92b656a54_menu.html.twig_fj-BpJf1XC9G7eBHeaYCj1LOd/WB6Ntjlr2B_-uGfqBdFthzyDCxnX-FSKTTMCEuXJ33s.php): Permission denied in Drupal\Component\PhpStorage\MTimeProtectedFastFileStorage->save() (line 88 of /home/site/wwwroot/core/lib/Drupal/Component/PhpStorage/MTimeProtectedFastFileStorage.php)
To the point it's bringing the sites to a crawl when drush runs.
Comment #15
smustgrave commentedComment #16
cilefen commentedHold on: are you seeing this bug or #2606772: Long Twig cache directories can cause failures on some filesystems? You commented there too. It’s probably not both.
Why “needs work”? There is a patch under review. Did you try it?
Comment #17
smustgrave commentedThat patch was from 6 years ago with Drupal 8.1
Doesn't apply to 9.2
Comment #18
smustgrave commentedBelieve this may be the issue though? The warning I posted in #14 seems closer at least.
Comment #19
smustgrave commentedWent ahead and rerolled the patch
Comment #20
smustgrave commentedComment #21
smustgrave commentedComment #22
smustgrave commentedComment #23
smustgrave commentedComment #27
larowlanThis came up as today's bugsmash target - is it still an issue?
Shouldn't these be written to a per host file system? e.g a /mnt/local or something that isn't shared across hosts?
Comment #28
jan-e commentedFWIW: on a Windows server I still had errors like this with an unpatched Drupal core 9.5.4 on March 7th:
Comment #29
kim.pepperWe do a lot more checks in
\Drupal\Core\File\FileSystem::movebut unfortunately,MTimeProtectedFastFileStorageis a component and can't depend on any other components or core services.