Make WordPress Core

Opened 3 weeks ago

#60855 new defect (bug)

wp_mkdir_p can error when simultaneous requests attempt to create the same directory

Reported by: grantmkin's profile grantmkin Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:


When two requests happen at the same time that both attempt to create a new directory with wp_mkdir_p, a race condition can occur that results in one request creating the directory and the other triggering an error.

The issue happens when both of the requests reach the file_exists check at nearly the same time:

The directory does not exist yet, so the check fails and both requests continue execution of the function. Then the requests are in a race to get to the code where the directory is actually created using mkdir:

The first request to reach that point will successfully create the directory and return true, the second will return false when mkdir fails because the directory already exists.

This causes an error upstream in the code because wp_mkdir_p is expected to return true when the directory already exists.

Found when testing the font library on new installs, see

Change History (0)

Note: See TracTickets for help on using tickets.