Description of the bug
We've recently updated a site from Wonolog 1.x to 3.x. We've since been getting a lot of WP HTTP API Error alerts (emailed to us due to our channel config). However, we believe the requests are actually succeeding.
Digging into the code, we can see that the impacted requests all pass these args to wp_remote_post or wp_remote_get:
...
'timeout'=>0.01,
'blocking'=>false
...
Looking at https://github.com/inpsyde/Wonolog/blob/3.x/src/HookListener/HttpApiListener.php, I can see that there is handling for blocking requests:
private function isError(array $response, array $httpArgs = []): bool
{
$responseData = $response['response'] ?? null;
$code = is_array($responseData) ? ($responseData['code'] ?? null) : null;
if (!$code || !is_numeric($code)) {
return true;
}
if (array_key_exists('blocking', $httpArgs) && !$httpArgs['blocking']) {
return false;
}
return !in_array((int) $code, self::HTTP_SUCCESS_CODES, true);
}
However, if we look at WP core, blocking requests always return a false code: https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/class-wp-http.php#L446
Therefore, I don't think the code ever hits the (array_key_exists('blocking', $httpArgs) && !$httpArgs['blocking']), as I believe (!$code || !is_numeric($code)) will always return true first.
I'm surprised no one else has reported this before (which makes me wonder if I'm overlooking something obvious!), but I think the two if conditions in isError should be swapped.
Reproduction instructions
See description
Expected behavior
See description
Environment info
Issue discovered on:
- WordPress 6.8.5
- Wonolog 3.0.2
Relevant log output
Additional context
No response
Code of Conduct
Description of the bug
We've recently updated a site from Wonolog 1.x to 3.x. We've since been getting a lot of
WP HTTP API Erroralerts (emailed to us due to our channel config). However, we believe the requests are actually succeeding.Digging into the code, we can see that the impacted requests all pass these args to
wp_remote_postorwp_remote_get:Looking at https://github.com/inpsyde/Wonolog/blob/3.x/src/HookListener/HttpApiListener.php, I can see that there is handling for
blockingrequests:However, if we look at WP core, blocking requests always return a
falsecode: https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/class-wp-http.php#L446Therefore, I don't think the code ever hits the
(array_key_exists('blocking', $httpArgs) && !$httpArgs['blocking']), as I believe(!$code || !is_numeric($code))will always return true first.I'm surprised no one else has reported this before (which makes me wonder if I'm overlooking something obvious!), but I think the two
ifconditions inisErrorshould be swapped.Reproduction instructions
See description
Expected behavior
See description
Environment info
Issue discovered on:
Relevant log output
Additional context
No response
Code of Conduct