8000 mkdir() race condition in ProxyCacheWarmer · Issue #47489 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

mkdir() race condition in ProxyCacheWarmer #47489

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

Closed
andrey-tech opened this issue Sep 5, 2022 · 3 comments
Closed

mkdir() race condition in ProxyCacheWarmer #47489

andrey-tech opened this issue Sep 5, 2022 · 3 comments

Comments

@andrey-tech
Copy link
Contributor

Symfony version(s) affected

4.4.44, up to 6.1.x

Description

The race condition is appears when several processes are attempting to create a same Doctrine Proxy directory which does not yet exist and \RuntimeException is thrown in \Symfony\Bridge\Doctrine\CacheWarmer\ProxyCacheWarmer at line 53:

51            if (!is_dir($proxyCacheDir = $em->getConfiguration()->getProxyDir())) {
52                if (false === @mkdir($proxyCacheDir, 0777, true)) {
53                    throw new \RuntimeException(sprintf('Unable to create the Doctrine Proxy directory "%s".', $proxyCacheDir));
54               }

How to reproduce

This issue is difficult to reproduce, as any concurrency-related issues are. It appears when several processes are attempting to create a directory which does not yet exist. Specifically, when one process is between !is_dir() and @mkdir() after another process has already managed to create the directory.

Possible Solution

Add an extra check to \Symfony\Bridge\Doctrine\CacheWarmer\ProxyCacheWarmer to line 52:

52                if (false === @mkdir($proxyCacheDir, 0777, true) && !is_dir($proxyCacheDir)) {

Additional Context

No response

@nicolas-grekas
Copy link
Member

Makes sense to me, can you please send a PR on branch 4.4?

nicolas-grekas added a commit that referenced this issue Sep 6, 2022
…ndrey-tech)

This PR was merged into the 4.4 branch.

Discussion
----------

[Bridge] Fix mkdir() race condition in ProxyCacheWarmer

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix [#47489](#47489)
| License       | MIT
| Doc PR        |  -

The race condition is appears when several processes are attempting to create a same Doctrine Proxy directory which does not yet exist and `\RuntimeException` is thrown in `\Symfony\Bridge\Doctrine\CacheWarmer\ProxyCacheWarmer`.

This PR adds an extra check to `\Symfony\Bridge\Doctrine\CacheWarmer\ProxyCacheWarmer`.

Commits
-------

cdb6c15 [Bridge] Fix mkdir() race condition in ProxyCacheWarmer
@andrey-tech
Copy link
Contributor Author

Do I need to send a PR on branch 6.1?

@nicolas-grekas
Copy link
Member

No need to, we'll merge 4.4 up to 6.2 soon.

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

No branches or pull requests

3 participants
0