Making WordPress.org


Ignore:
Timestamp:
09/29/2020 12:37:30 AM (4 years ago)
Author:
dd32
Message:

Plugin Directory: Search: Retry search queries when a API->ES timeout is encountered.

The volume of affected queries is low, but high enough that it's annoying on WordPress.org error logging.
This simply retries the query when the error rates are low (ie. ES is probably not unresponsive/overloaded, and the network isn't having issues) which means this shouldn't exacerbate any real errors.

Hopefully quietens the PHP Warnings related to Search timeouts, and fixes search results for the 1 in a million end-users who we didn't have a stale cache for.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/libs/site-search/jetpack-search.php

    r10228 r10293  
    194194     */
    195195    protected function error_volume_is_low() {
    196         // This cache key keeps a global-ish count of recent errors (per memcache instance).
     196        // This cache key keeps a global-ish count of recent errors.
    197197        // Used for random exponential backoff when errors start to pile up, as they will if there is a network outage for example.
    198198        $error_volume = max( $this->get_error_volume(), 0 ); // >= 0
     
    251251            // If the error volume is high, there's a proportionally lower chance that we'll actually attempt to hit the API.
    252252            if ( $this->error_volume_is_low() ) {
    253                 $request = wp_remote_post( $service_url, array(
     253                $service_args = array(
    254254                    'headers'    => array(
    255255                        'Content-Type' => 'application/json',
     
    258258                    'user-agent' => 'WordPress.org/jetpack_search',
    259259                    'body'       => $json_es_args,
    260                 ) );
     260                );
     261                $request = wp_remote_post( $service_url, $service_args );
    261262            } else {
    262263                trigger_error( 'Plugin directory search: skipping search due to high error volume', E_USER_WARNING );
    263264                // Hopefully we still have a cached response to return
    264265                return $response;
     266            }
     267
     268            // Retry 400 responses if the error volume is still low.
     269            // These 400's are not bad requests but rather timeouts between the API and ES
     270            if ( 400 === wp_remote_retrieve_response_code( $request ) ) {
     271                // Bump the error counter
     272                $this->increment_error_volume();
     273
     274                if ( $this->error_volume_is_low() ) {
     275                    $request = wp_remote_post( $service_url, $service_args );
     276                }
    265277            }
    266278
Note: See TracChangeset for help on using the changeset viewer.