Review 13.4 Merged

87644[BUGFIX] Prevent race condition while writing file caches

Benjamin Franzke CR +2 V +2 Normal +36 −29 updated 01/07/25, 08:13

Commit message

Whenever a cache entry is written via the cache file backends,
two race conditions could previously happen when a parallel flush
is in action:

a) The temporary file is trying to be written to a folder that is
   currently not available, because it has been moved, but not
   recreated yet. The time frame for this race condition should
   have been quite slow, but it's still the error we saw most of
   the times, which likely happened often due to stale NFS caches.

b) The temporary cache (that is created in a file named `{random}.temp`)
   could be written to the cache directory, but is (re)moved to another
   directory because a parallel `flush()` moves the containing folder to
   a temporary folder, in order to delete it afterwards.
   That means the temporary file can then still be written to (as long
   as the folder is still being deleted, the kernel file descriptor that
   PHP writes to is still valid), but the subsequent `rename` operation
   will fail because the temporary file is tried to be renamed (moved)
   from the "old" location (within the original cache folder), but is no
   longer stored there.

In order to prevent both race conditions, cache folders are no
longer removed. Only the containing cache files are deleted.

The temporary cache files are now created in a separate tmp-files
subfolder, in order to not be removed by a parallel flush operation.

Review

  • Code review CR +2 Done
    • Benjamin Franzke +2
  • Verified V +2 Done
    • Benjamin Franzke +2
    • core-ci +1 CI

Issues 1

Files 2

Review log 45

  1. Benjamin Franzke commented on patch set 1 01/06/25, 12:18

    Cherry Picked from branch main.
  2. Benjamin Franzke marked it work in progress 01/06/25, 12:18

  3. core-ci voted on patch set 1 V +1 01/06/25, 12:25 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/71983

  4. Benjamin Franzke commented on patch set 1 CR +2 V +2 01/07/25, 08:13

    This change is ready for review.
  5. Benjamin Franzke merged patch set 2 01/07/25, 08:13