[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.


 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