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.

Comments

david_garcia created an issue. See original summary.

david_garcia’s picture

Status: Active » Needs review
StatusFileSize
new3.96 KB
david_garcia’s picture

There 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 :(

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

mxr576’s picture

Version: 8.9.x-dev » 9.2.x-dev
Issue tags: +concurrency, +race condition

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

ghost of drupal past’s picture

Well, that's surprising.

https://www.drupal.org/project/drupal/issues/2547827#comment-10213679

We do not solve No2. We make it so that the coordination is unnecessary across webheads for core usages. To achieve this, we do one off hacks to Twig (so it becomes write once)

I will dig more. This was supposedly solved before 8.0 came out, something apparently went sideways.

smustgrave’s picture

Wonder 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.

smustgrave’s picture

Status: Needs review » Needs work
cilefen’s picture

Hold 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?

smustgrave’s picture

That patch was from 6 years ago with Drupal 8.1

Doesn't apply to 9.2

smustgrave’s picture

Believe this may be the issue though? The warning I posted in #14 seems closer at least.

smustgrave’s picture

Went ahead and rerolled the patch

smustgrave’s picture

smustgrave’s picture

smustgrave’s picture

smustgrave’s picture

StatusFileSize
new5.3 KB

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

larowlan’s picture

Issue tags: +Bug Smash Initiative

This 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?

jan-e’s picture

FWIW: on a Windows server I still had errors like this with an unpatched Drupal core 9.5.4 on March 7th:

rename(sites/default/files/php/twig/.nnWfgPodASaFePa8_7gFfmFafwU,sites/default/files/php/twig/640195f90bf17_menu.html.twig_xdiNudfk9QDvOGCiabMF4fGea/LMmSAN4RIDKvzVj8xqiNkyiUGaUVCMjw0NifP6zjx-4.php): Access is denied (code: 5) in Drupal\Component\PhpStorage\MTimeProtectedFastFileStorage->save() (line 88 of core\lib\Drupal\Component\PhpStorage\MTimeProtectedFastFileStorage.php)

kim.pepper’s picture

We do a lot more checks in \Drupal\Core\File\FileSystem::move but unfortunately, MTimeProtectedFastFileStorage is a component and can't depend on any other components or core services.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.