MTimeProtectedFastFileStorage crashes with concurrency.

Created on 4 April 2016, about 8 years ago
Updated 20 March 2023, over 1 year ago

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.

πŸ› Bug report
Status

Needs work

Version

10.1 ✨

Component
File systemΒ  β†’

Last updated about 4 hours ago

Created by

πŸ‡ͺπŸ‡ΈSpain david_garcia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    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?

  • πŸ‡³πŸ‡±Netherlands Jan-E

    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)

  • πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia

    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.

Production build 0.69.0 2024