Req #35326 [Com]: Concurrency issue with recursive mkdir
| From: | toonitw at gmail dot com | Date: | Mon, 06 Dec 2021 18:54:30 +0000 |
| Subject: | Req #35326 [Com]: Concurrency issue with recursive mkdir | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-238225@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=35326&edit=1
ID: 35326
Comment by: toonitw at gmail dot com
Reported by: bugs dot php dot net at chsc dot dk
Summary: Concurrency issue with recursive mkdir
Status: Not a bug
Type: Feature/Change Request
Package: *General Issues
Operating System: Linux
PHP Version: 5.1.6
Block user comment: N
Private report: N
New Comment:
Fixed in 8.1
https://github.com/php/php-src/pull/7383
Previous Comments:
------------------------------------------------------------------------
[2018-08-21 19:23:57] nasretdinov at gmail dot com
You do not need any locking at all. mkdir() returns EEXIST when directory exists and it should not
be treated as error in this function. "mkdir -p" does this, for example.
------------------------------------------------------------------------
[2013-10-30 10:13:35] gustavo dot straube at gmail dot com
> We don't need a locking mechanism. If the creation of a directory fails, we just need to
> check if it exists anyway [...]
In the application I experienced this bug, I do have a condition before the directory creation.
1. if (!is_dir($path))
2. mkdir($path, 0755, true);
If I have two concurrent process ("A" and "B") running the code in this order
(process - line):
A - 1
B - 1
B - 2
A - 2
When process "A" verified the directory existence, it really didn't exist.
------------------------------------------------------------------------
[2013-10-30 08:49:24] bugs dot php dot net at chsc dot dk
> To create the right locking mechanism to avoid such issue to happen
We don't need a locking mechanism. If the creation of a directory fails, we just need to check
if it exists anyway (i.e. it has been created by a concurrent thread). If it does, we can proceed to
create the subdirectories.
------------------------------------------------------------------------
[2013-10-01 04:52:05] pajoye@php.net
Update the status.
And adding a small note about "why is it not a php bug", what is described here
can happen anywhere outside php as well, be a shell script, ftp/ssh, etc.
------------------------------------------------------------------------
[2013-10-01 04:21:25] pajoye@php.net
Should have been:
... and will drastically affect performance without actually solving the
problem....
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=35326
--
Edit this bug report at https://bugs.php.net/bug.php?id=35326&edit=1