Skip to content

fix race condition at mkdir (#16258) #16292

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
wants to merge 6 commits into from
Closed

fix race condition at mkdir (#16258) #16292

wants to merge 6 commits into from

Conversation

ewgRa
Copy link
Contributor

@ewgRa ewgRa commented Oct 19, 2015

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #16258
License MIT
Doc PR

@ewgRa
Copy link
Contributor Author

ewgRa commented Oct 19, 2015

I'm not sure is IOException in this case broke BC.

@@ -42,7 +44,9 @@ public function __construct($dsn)
$this->folder = substr($dsn, 5);

if (!is_dir($this->folder)) {
mkdir($this->folder, 0777, true);
if (false === @mkdir($this->folder, 0777, true) && !is_dir($this->folder)) {
throw new IOException(sprintf('Unable to create the storage directory (%s).', $this->folder));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The HttpKernel should not need to know the Filesystem Component exceptions. Simply use \RuntimeException

@Tobion
Copy link
Contributor

Tobion commented Oct 20, 2015

@Tobion
Copy link
Contributor

Tobion commented Oct 20, 2015

Status: Needs Work

@ewgRa
Copy link
Contributor Author

ewgRa commented Oct 20, 2015

@Tobion Thanks for review

The HttpKernel should not need to know the Filesystem Component exceptions

Where I can read more? It is quite strange, HttpKernel work with disk, but throw RuntimeException instead of IOException. And what If I want to find all code that work with IO? With IOException it is more obvious.

Status: Needs Review

@jvasseur
Copy link
Contributor

@ewgRa The HttpKernel doesn't have any dependency on the filesystem component, using an exception would require to add it.

@ewgRa
Copy link
Contributor Author

ewgRa commented Oct 20, 2015

@jvasseur Thanks! Check composer at components and understand now that they can be used separately. Good to know.

@juanperi
Copy link

I've seen this also happening at https://github.com/symfony/symfony/blob/2.8/src/Symfony/Component/HttpKernel/HttpCache/Store.php#L40

Edit: Should that be fixed also?

@ewgRa
Copy link
Contributor Author

ewgRa commented Oct 20, 2015

@epilgrim I think you are right. Checks added in HttpCache in three places where mkdir called.

@ewgRa
Copy link
Contributor Author

ewgRa commented Oct 20, 2015

Done. Previous build seems have random hhvm test fail.

@SpacePossum
Copy link
Contributor

(for ref.: #14728 (please ignore))

@fabpot
Copy link
Member

fabpot commented Nov 4, 2015

👍 should be merged in 2.3 as this is a bug fix.

@fabpot
Copy link
Member

fabpot commented Nov 7, 2015

Thank you @ewgRa.

fabpot added a commit that referenced this pull request Nov 7, 2015
This PR was submitted for the 2.8 branch but it was merged into the 2.3 branch instead (closes #16292).

Discussion
----------

fix race condition at mkdir (#16258)

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #16258
| License       | MIT
| Doc PR        |

Commits
-------

2c2836c fix race condition at mkdir (#16258)
@fabpot fabpot closed this Nov 7, 2015
@ewgRa ewgRa deleted the issue-16258-race-condition branch November 7, 2015 09:15
*/
public function __construct($root)
{
$this->root = $root;
if (!is_dir($this->root)) {
mkdir($this->root, 0777, true);
if (false === @mkdir($this->root, 0777, true) && !is_dir($this->root)) {
throw new \RuntimeException(sprintf('Unable to create the store directory (%s).', $this->root));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: storage

This was referenced Nov 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants