[wp-trac] [WordPress Trac] #60855: wp_mkdir_p can error when simultaneous requests attempt to create the same directory

WordPress Trac noreply at wordpress.org
Fri May 17 14:24:17 UTC 2024


#60855: wp_mkdir_p can error when simultaneous requests attempt to create the same
directory
--------------------------+------------------------------
 Reporter:  grantmkin     |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  General       |     Version:
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Comment (by siliconforks):

 Replying to [comment:1 peterwilsoncc]:
 > The only technique I've been able to think of to resolve this issue is
 to use the a collision avoidance technique similar to that used by
 computer networks.
 >
 > If calling `mkdir()` fails the first time, back of for `usleep( wp_rand(
 50, 250000 ) )` and try a second time. As the file system may not actually
 be writable, I think if it fails the second time it's safe to assume the
 issue is not a collision. The lower and upper limit would need to be
 figured out.
 >
 > I don't love this solution so it would be nice to hear of other
 suggestions for resolving the race condition.

 I'm not sure I understand why it needs to "try a second time"?  If the
 directory has already been created, then nothing more would need to be
 done, right?

 Or maybe you mean it needs to check whether the directory exists a second
 time?  That could work, although I'm not sure why the time sleeping would
 need to be random in that case.  Actually, I'm not sure it would need to
 sleep at all.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60855#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list