stale_response: handle TS API failures instead of ignoring them - #13592
Draft
bryancall wants to merge 1 commit into
Draft
stale_response: handle TS API failures instead of ignoring them#13592bryancall wants to merge 1 commit into
bryancall wants to merge 1 commit into
Conversation
Several call sites discarded a TSReturnCode and then used an output parameter the failing call never wrote. TSHttpHdrUrlGet returns TS_ERROR without touching *locp when the header is not a request, so an uninitialized TSMLoc reached UrlComponents::populate(), TSUrlHttpQuerySet() and TSHandleMLocRelease() in three functions. create_request_info() had the same problem with TSHttpTxnClientReqGet and TSHttpHdrClone, storing a garbage TSMLoc in a TSmalloc'd structure that lives for the whole transaction. Check these calls, log through the plugin's existing tags, and bail the way neighboring code already does. create_request_info() now returns nullptr on failure and its callers handle that. strip_trailing_parameter() reports false when the query rewrite itself fails, rather than claiming a strip that did not happen. Note that on a TSUrlParse failure the URL has already been cleared by the API before parsing begins, so that path still continues with an emptied URL. This change makes that visible in the logs rather than silent; repairing it needs a separate fix.
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.
Several call sites in the
stale_responseplugin discarded aTSReturnCodeand then used an output parameter that the failing call never wrote.The bug
TSHttpHdrUrlGetreturnsTS_ERRORwithout touching*locpwhen the header is not a request. The plugin did this in three functions:On the failure path
url_lockeeps stack garbage and is passed toUrlComponents::populate(), then toTSUrlHttpQuerySet()orTSUrlParse(), and finally toTSHandleMLocRelease().create_request_info()had the same shape withTSHttpTxnClientReqGetandTSHttpHdrClone. That one is worse:req_infocomes fromTSmalloc()and is not zeroed, so a garbageTSMLocis stored in a structure that lives for the whole transaction and is later handed toTSMimeHdrFieldFind,TSHttpHdrPrint, andTSHandleMLocRelease.strip_trailing_parameter()also setstripped = truebefore callingTSUrlHttpQuerySet()and ignored its result, so it reported success even when the URL was never rewritten.What changed
Check these calls, log through the plugin's existing debug tags, and bail the way neighboring code in the same file already does (
get_pristine_url()andintercept_check_request()were already checking the identical call).create_request_info()now returnsnullptron failure and its callers handle that.TSHttpTxnEffectiveUrlStringGetis null-checked before being passed toTSstrndup.Known limitation, not addressed here
On a
TSUrlParsefailure inadd_trailing_parameter(), the URL has already been cleared by the API before parsing begins, so that path continues with an emptied URL. This change makes the failure visible in the logs rather than silent, but does not repair the URL. Doing that properly means snapshotting the original and restoring it, which is a behavior change that belongs in its own patch.Testing
The plugin builds clean. The changes were reviewed specifically for new leaks and double-releases on the added error paths.