fix: handle concurrent mkdir race condition in FileSystemCache#787
Merged
romm merged 3 commits intoCuyZ:masterfrom Mar 1, 2026
Merged
fix: handle concurrent mkdir race condition in FileSystemCache#787romm merged 3 commits intoCuyZ:masterfrom
romm merged 3 commits intoCuyZ:masterfrom
Conversation
Contributor
Author
|
Sorry for LLM) |
…-directory-mkdir-race-condition
Member
|
Thank you for the PR. 😊 I'd have preferred a description written by hand, but at least you had the honesty to tell it was written by an LLM. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When multiple workers (e.g., Laravel Octane, queue workers) start simultaneously,
FileSystemCache::set()throwsCacheDirectoryNotWritabledue to a race condition.The current code:
Race condition scenario:
is_dir($tmpDir)→false→@mkdir()→true✅ (created)is_dir($tmpDir)→false→@mkdir()→false(already exists) →CacheDirectoryNotWritable💥@mkdir()suppresses the PHP warning but still returnsfalsewhen the directory already exists. Without a secondis_dir()check, a concurrent process that lost the race throws an exception even though the directory was successfully created by another process.This issue was previously reported in #401 and partially addressed in #407 (warmup pre-creation), but the race condition in
set()itself remains.Fix
Add the standard triple-check pattern used throughout PHP ecosystem for atomic directory creation:
The third
is_dir()check confirms the directory truly doesn't exist aftermkdir()failure — distinguishing a genuine error (permissions, disk full) from a concurrent creation by another process.Related
@suppression problem with Laravel's error handler