[wp-trac] [WordPress Trac] #51962: Race condition in wp_get_custom_css_post() would clear the custom CSS entry
WordPress Trac
noreply at wordpress.org
Tue Dec 8 03:11:04 UTC 2020
#51962: Race condition in wp_get_custom_css_post() would clear the custom CSS entry
--------------------------+-----------------------------
Reporter: candrei | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 5.5.3
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
Our production system was recently affected by a (what it looks to me)
race condition in `wp_get_custom_css_post()`; for reference here's the
code in question:
{{{#!php
if ( get_stylesheet() === $stylesheet ) {
$post_id = get_theme_mod( 'custom_css_post_id' );
if ( $post_id > 0 && get_post( $post_id ) ) {
$post = get_post( $post_id );
}
// `-1` indicates no post exists; no query necessary.
if ( ! $post && -1 !== $post_id ) {
$query = new WP_Query( $custom_css_query_vars );
$post = $query->post;
/*
* Cache the lookup. See
wp_update_custom_css_post().
* @todo This should get cleared if a custom_css
post is added/removed.
*/
set_theme_mod( 'custom_css_post_id', $post ?
$post->ID : -1 );
}
} else {
}}}
Our database went down after retrieving the `$post_id` from options.
`get_post()` failed silently followed by `new WP_Query(
$custom_css_query_vars );` that failed too while the DB was down.
Eventually the DB became available and the `custom_css_post_id` setting
was set to `-1`.
As a result our website's styling was affected until we were able to
restore the custom CSS stored in the `custom_css` post.
I think better error handling within the `wp_get_custom_css_post()` could
prevent such side effect from taking place.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51962>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list