Skip to content

[Caching] Use FileSystem::writeAtomic() in FileCacheStorage to avoid partial cache reads on parallel run - #8520

Merged
TomasVotruba merged 4 commits into
mainfrom
atomic-cache-write-file-system
Sep 29, 2026
Merged

TomasVotruba merged 4 commits into
mainfrom
atomic-cache-write-file-system

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Alternative to #8426, following the suggestion to drop the hand-rolled workarounds and reuse Nette\Utils\FileSystem::writeAtomic() (added in nette/utils 4.1.5, cc0326d).

Problem

On parallel runs, save() used copy() to publish the cache file. copy() truncates the destination and streams into it, so it is not atomic - a concurrent worker that require()s the same path during boot can read a half-written file and crash:

{"fatal_errors":["syntax error, unexpected string content ..."]}
 [ERROR] Could not process some files, due to: "Child process error".

This hits Linux too, not only Windows.

Change

Fixes rectorphp/rector#9876

@TomasVotruba
TomasVotruba merged commit d6b205a into main Sep 29, 2026
47 checks passed
@TomasVotruba
TomasVotruba deleted the atomic-cache-write-file-system branch September 29, 2026 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

FileCacheStorage uses copy() instead of rename(), corrupting cache files on parallel cold-cache runs

1 participant