[wp-trac] [WordPress Trac] #55952: add_option() racy behaviour
WordPress Trac
noreply at wordpress.org
Thu Jun 9 00:16:00 UTC 2022
#55952: add_option() racy behaviour
--------------------------------+-----------------------------
Reporter: karl94 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Options, Meta APIs | Version:
Severity: normal | Keywords:
Focuses: |
--------------------------------+-----------------------------
If two or more processes try to add an option via `add_option()` at the
same time with both the same value, the following calls to `get_option()`
may return `false` as if the option wasn't set.
This happens for example if two processes A and B: both reach past the
check in https://github.com/WordPress/wordpress-develop/blob/6.0/src/wp-
includes/option.php#L622-L624 before any of the two performs the `INSERT`.
In this scenario, the first process which gets to execute the `INSERT`
will return `true` and will have the correct value in its object cache.
The other process's `add_option()` will return `false` and it's object
cache will continue to believe the option doesn't exists.
https://github.com/WordPress/wordpress-develop/blob/6.0/src/wp-
includes/option.php#L640-L641
https://github.com/WordPress/wordpress-develop/blob/6.0/src/wp-includes
/wp-db.php#L2116-L2131
https://dev.mysql.com/doc/refman/8.0/en/insert-on-
duplicate.html#:~:text=0%20if%20an%20existing%20row%20is%20set%20to%20its%20current%20values
You can find attached a plugin designed for testing this race condition.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/55952>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list