Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CreateDestinationFolderException: mkdir race condition #328

Open
AlexeyKosov opened this issue Jan 14, 2022 · 0 comments
Open

CreateDestinationFolderException: mkdir race condition #328

AlexeyKosov opened this issue Jan 14, 2022 · 0 comments

Comments

@AlexeyKosov
Copy link

AlexeyKosov commented Jan 14, 2022

When a browser sends many requests for image conversion concurrently (e.g. an image gallery is loaded) and the destination directory does not exist, every request tries to create the directory, which ends up with CreateDestinationFolderException because of a race condition.

So instead of

if (! is_dir($dir) && ! mkdir($dir, 0777, true)) {
    throw new CreateDestinationFolderException();
}

the following should be used:

if (! is_dir($dir) && ! mkdir($dir, 0777, true) && ! is_dir($dir)) {
    throw new CreateDestinationFolderException();
}

(code is simplified)

More info about this issue:

https://www.google.com/search?q=php+mkdir+race+condition
https://bugs.php.net/bug.php?id=35326
https://stackoverflow.com/questions/44322783/is-is-dir-unreliable-or-are-there-race-conditions-that-can-be-mitigated-here/57939677#57939677
https://app.bountysource.com/issues/49427500-mkdir-race-condition-enhancement
symfony/symfony#11626

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant