[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 01:38:44 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 peterwilsoncc):

 This is also reproducible via the block editor when uploading media.

 Reproduction steps

 1. Start with a fresh install or run `wp site empty`
 2. Delete the uploads directory
 3. Open a new post
 4. In your file system, select multiple image files for uploading
 5. Drag these in to the editor (to create a gallery block)
 6. This will cause the browser to make multiple, parallel requests to
 upload the images.
 7. One of the uploads may fail due to the race condition in
 `wp_mkdir_p()`.

 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.

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


More information about the wp-trac mailing list