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:

Description

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:

https://github.com/WordPress/wordpress-develop/blob/e73db80196c0044503633bda41511258a9516a8b/src/wp-includes/functions.php#L2059

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:

https://github.com/WordPress/wordpress-develop/blob/e73db80196c0044503633bda41511258a9516a8b/src/wp-includes/functions.php#L2082

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 https://github.com/WordPress/gutenberg/issues/59023#issuecomment-2022746082

Change History (0)

Note: See TracTickets for help on using tickets.