You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On an open source PHP application I work on, we sometimes have issues reported by administrators related to unexpected filesystem saturation. The impacted cache namespace is supposed to contains only a dozen of items, but the directory contains 250k files located at its root. These files are temporary files generated when a cache entry is updated, and are supposed to be removed automatically.
The problem is that the target file is exists, contains stale information, but is not writable.
First, let's resume what is done by the Filesystem apadter when a cache entry is written:
a temporary file is created at the root of the cache directory;
content is written inside this file;
this file is renamed to its target path, using the PHP rename() function.
Make the corresponding file read-only on the filesystem.
Update the cache entry.
-> The temporary file created on the cache directory root is not deleted.
Possible Solution
On Symfony 4.4, a cleaning operation was always done after the rename, see #39059. I think it could be simple to put back this cleaning operation, to prevent filesystem saturation.
Additional Context
No response
The text was updated successfully, but these errors were encountered:
My bad, one of the target file was existing but was not writable. I thought an exception would be triggered, but it is in fact catched internally by Symfony.
…lure (cedric-anne)
This PR was squashed before being merged into the 5.4 branch.
Discussion
----------
[Cache] Remove temporary cache item file on `rename()` failure
| Q | A
| ------------- | ---
| Branch? | 5.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | Fix#52092
| License | MIT
The filesystem cache adapter creates a temporary file to store cache item data, then moves it to its target path using `rename()` function. If rename fails, for instance target path is not writable, the temporary file will remains.
To prevent filesystem saturation, the temporary files should be deleted if this operation is not done by the `rename()` function itself.
Commits
-------
af15423 [Cache] Remove temporary cache item file on `rename()` failure
Symfony version(s) affected
5.x, 6.x
Description
On an open source PHP application I work on, we sometimes have issues reported by administrators related to unexpected filesystem saturation. The impacted cache namespace is supposed to contains only a dozen of items, but the directory contains 250k files located at its root. These files are temporary files generated when a cache entry is updated, and are supposed to be removed automatically.
The problem is that the target file is exists, contains stale information, but is not writable.
First, let's resume what is done by the Filesystem apadter when a cache entry is written:
rename()
function.Related code:
symfony/src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php
Lines 88 to 114 in d69ab75
Now, let's see what the
rename()
function do:If any of the 3 first steps fails, the unlink is not done.
Related code: https://github.com/php/php-src/blob/221b4fe246e62c5d59f617ee4cbe6fd4c614fb5a/main/streams/plain_wrapper.c#L1272-L1371
How to reproduce
-> The temporary file created on the cache directory root is not deleted.
Possible Solution
On Symfony 4.4, a cleaning operation was always done after the rename, see #39059. I think it could be simple to put back this cleaning operation, to prevent filesystem saturation.
Additional Context
No response
The text was updated successfully, but these errors were encountered: