WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#15545 closed defect (bug) (fixed)

When using a persistent cache, there is a race condition in get_metadata()

Reported by: mdawaffe Owned by: markjaquith
Milestone: 3.1 Priority: normal
Severity: normal Version: 3.1
Component: Cache API Keywords: has-patch
Focuses: Cc:

Description

get_metadata() does:

update_meta_cache($meta_type, $object_id);
$meta_cache = wp_cache_get($object_id, $meta_type . '_meta');

When using a persistent cache, another process could delete the cached data between the first and second lines there, resulting in a value of false for $meta_cache.

This can cause users to be cached without meta data (rare) or get_blogs_of_user() to cache empty arrays (common).

Attached updates update_meta_cache() to always return valid (if perhaps out of date) information for all requested IDs, not just the previously uncached IDs.

Attached also uses this update to simplify get_user_metavalues().

To prevent storing out of date information, wp_cache_add() should probably be used with update_meta_cache() data (as opposed to wp_cache_set()): users, *_meta, etc. I didn't audit everything (and I'm not positive it's a concern), so this patch doesn't address the above add v. set guideline. get_blogs_of_user() should probably do an add instead of a set, though....

This patch is currently running on WordPress.com without problem... so far :)

Attachments (1)

15545.diff (2.0 KB) - added by mdawaffe 3 years ago.

Download all attachments as: .zip

Change History (4)

mdawaffe3 years ago

comment:1 ryan3 years ago

(In [16596]) Meta data caching improvements. Props mdawaffe. see #15545

comment:2 ryan3 years ago

  • Resolution set to fixed
  • Status changed from new to closed

comment:3 markjaquith3 years ago

  • Owner set to markjaquith

(nevermind)

Version 1, edited 3 years ago by markjaquith (previous) (next) (diff)
Note: See TracTickets for help on using tickets.