Fix fatal error when pre_http_request response is never logged#1071
Open
trajche wants to merge 1 commit intojohnbillion:developfrom
Open
Fix fatal error when pre_http_request response is never logged#1071trajche wants to merge 1 commit intojohnbillion:developfrom
trajche wants to merge 1 commit intojohnbillion:developfrom
Conversation
When a plugin hooks `pre_http_request` at a priority higher than QM's (9999), QM's own `filter_pre_http_request` callback runs first and sees no interception yet (response is still false). The later plugin then intercepts and returns a non-false value, causing WordPress to short-circuit the request. This means `http_api_debug` never fires, so no entry is ever added to `$this->http_responses` for that key. When `process()` later iterates `$this->http_requests` and accesses `$this->http_responses[$key]`, the missing key causes an `ErrorException: Undefined array key` on PHP 8.x. Fix by checking whether the response was captured before accessing it. If not, synthesise a fallback using `http_request_not_executed` — the same error code already used for nested-request edge cases (line 297) and already present in the default `qm/collect/silent_http_errors` list, so it won't generate a spurious alert. Fixes johnbillion#811
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #811
Root cause
QM hooks both
http_request_argsandpre_http_requestat priority 9999. When a plugin hookspre_http_requestat a higher priority (e.g. 10000), the execution order is:filter_pre_http_requestruns at priority 9999 → sees$response === false, returns early without logginghttp_api_debugnever firesResult: the request is stored in
$this->http_requests(viahttp_request_args) but nothing is ever written to$this->http_responses. Whenprocess()accesses$this->http_responses[$key], PHP 8.x throwsErrorException: Undefined array key.Known triggers: wp-china-yes, Polylang Pro update checks, security plugins that block external requests.
Fix
Check whether a response was captured before accessing it. If not, synthesise a fallback with
http_request_not_executedthe sameWP_Errorcode already used for nested-request edge cases (line 297) and already in the defaultqm/collect/silent_http_errorslist, so it won't generate a spurious alert.How to reproduce
Drop this in
mu-plugins/qm-bug-repro.phpand visit/?trigger_qm_bug=1:Co-authored with Claude^