You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@trafficserver.apache.org by "bryancall (via GitHub)" <gi...@apache.org> on 2026/09/17 22:04:51 UTC

[PR] Fix cache_fill range request detection and a Content-Length config gap [trafficserver]

bryancall opened a new pull request, #13704:
URL: https://github.com/apache/trafficserver/pull/13704

   ### The bug
   
   `BgFetchConfig::bgFetchAllowed()` decides whether a transaction is a range
   request by looking for a `Range` or conditional header. The lookup had a
   misplaced closing paren:
   
   ```cpp
   if (TSMimeHdrFieldFind(bufp, hdr_loc, header.data(), header.size() == TS_SUCCESS)) {
   ```
   
   `TSMimeHdrFieldFind()` returns a `TSMLoc`, not a `TSReturnCode`, so the
   `== TS_SUCCESS` belonged on the call rather than on the length argument.
   `TS_SUCCESS` is `0`, so `header.size() == TS_SUCCESS` evaluated to `false`,
   which converted to a length of `0`. The plugin was searching every request for
   a zero-length field name, which never matches.
   
   A zero-length name is not merely a lookup that misses. `mime_hdr_field_find()`
   asserts on it:
   
   ```
   Fatal: src/proxy/hdrs/MIME.cc:1224: failed assertion `!field_name.empty()`
   traffic_server: received signal 6 (Aborted)
   ```
   
   That is an `ink_assert`, which is compiled out in release builds, so the
   behaviour split by build type:
   
   - **debug builds abort** on the first request through a remap rule that sets
     either option
   - **release builds** carry on with `hasRangeHdrs` always `false`, leaving both
     options broken in opposite directions:
   
   | Option | Intended | Actual (release) |
   |---|---|---|
   | `--range-req-only=true` | background fill only for range requests | never filled, including for range requests |
   | `--cache-range-req=false` | suppress the fill for range requests | never suppressed anything |
   
   ### The fix
   
   Pass the name length and test the returned handle. Since the broken call could
   only ever return `TS_NULL_MLOC`, it never had a handle to release; now that the
   lookup can succeed, the field handle is released, as is the header handle from
   `TSHttpTxnClientReqGet()`. `TSMimeHdrFieldFind()`'s contract in `ts.h` asks for
   the former; the latter was already leaking on every call into this block.
   
   Also reject a `Content-Length` condition that carries no size value, the way
   `plugins/background_fetch` already does. Without it, `++cfg_value` leaves the
   view empty, `swoc::svtou()` sets `parsed` empty too, so the
   `parsed.size() != cfg_value.size()` guard compares `0 != 0`, passes, and a
   `<= 0` rule is installed from a config line that specified no size at all.
   
   ### Testing
   
   New autest `cache_fill_range_req_only`, driving both directions of the
   `--range-req-only=true` decision so that a fix which simply always filled would
   not pass:
   
   - a range request must fill the cache (second request is `hit-fresh` / `206`)
   - a plain request must not (stays a miss)
   
   Verified it discriminates, by rebuilding the plugin with the paren restored and
   re-running: the test fails, and the autest build aborts on the assertion above.
   With the fix, `cache_fill` and `cache_fill_range_req_only` both pass and no
   crash log is produced.
   
   The existing `cache_fill` gold test is unaffected, and that is itself the
   reason this survived: `_range_req_only` defaults to `false` and
   `_cache_range_req` to `true`, so `if (_range_req_only || !_cache_range_req)`
   is false under the default config and the whole block was never entered by any
   existing test.
   
   Neither of these was flagged by Coverity. They turned up while reading
   `plugins/background_fetch` and `plugins/experimental/cache_fill` side by side,
   which is worth doing on its own -- `cache_fill` was forked from
   `background_fetch` and the two have drifted.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix cache_fill range request detection and a Content-Length config gap [trafficserver]

Posted by "bryancall (via GitHub)" <gi...@apache.org>.
bryancall merged PR #13704:
URL: https://github.com/apache/trafficserver/pull/13704


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix cache_fill range request detection and a Content-Length config gap [trafficserver]

Posted by "bryancall (via GitHub)" <gi...@apache.org>.
bryancall commented on PR #13704:
URL: https://github.com/apache/trafficserver/pull/13704#issuecomment-5722763551

   Thanks — I added the `--cache-range-req=false` case. That was a fair catch: no test in the tree set either option before this, and since the same header lookup drives both, that branch had no coverage at all. It also turns out to be an independent check on this fix rather than just extra breadth — under the broken lookup `hasRangeHdrs` was always false, so `hasRangeHdrs && !_cache_range_req` never ran either. I confirmed that by rebuilding the plugin with the paren restored: the new case fails on its own.
   
   While adding it I folded the range-option coverage into the existing `cache_fill.test.py` instead of a separate file, in its own ATS process. It cannot share the existing one, because that test loads `cache_fill` globally with default options, and a global instance hooks every transaction — it would background fill these paths regardless of the per-remap options and make the negative cases vacuous.
   
   On coverage for the incomplete `Content-Length` rule: I am leaving that one out deliberately. The only observable behavior is a `TSError` line, so a test for it would assert on a log message and need its own ATS instance for a config-parse path, which I do not think earns its keep here. Noting it so it does not look overlooked.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix cache_fill range request detection and a Content-Length config gap [trafficserver]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #13704:
URL: https://github.com/apache/trafficserver/pull/13704#discussion_r4041836643


##########
plugins/experimental/cache_fill/configs.cc:
##########
@@ -168,6 +168,10 @@ BgFetchConfig::readConfig(const char *config_file)
             continue;
           }
           ++cfg_value; // Drop leading character.
+          if (cfg_value.empty()) {
+            TSError("[%s] missing Content-Length size value, skipping config value", PLUGIN_NAME);
+            continue;
+          }

Review Comment:
   Please add a regression case for a `Content-Length` condition containing only `<` or `>`. The new guard is not exercised by `cache_fill_range_req_only`, and the existing analogous `background_fetch` test covers only valid numeric rules, so a future regression could again install a zero-sized rule without being detected.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix cache_fill range request detection and a Content-Length config gap [trafficserver]

Posted by "bneradt (via GitHub)" <gi...@apache.org>.
bneradt commented on PR #13704:
URL: https://github.com/apache/trafficserver/pull/13704#issuecomment-5770182696

   [approve ci autest 2]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix cache_fill range request detection and a Content-Length config gap [trafficserver]

Posted by "bryancall (via GitHub)" <gi...@apache.org>.
bryancall commented on PR #13704:
URL: https://github.com/apache/trafficserver/pull/13704#issuecomment-5725573033

   Correcting my own description: I overstated the severity, and the original text was up for a few hours, so the correction is worth stating rather than quietly editing.
   
   I wrote that release builds had both options broken and that the header handle was leaking. Both are wrong.
   
   `mime_hdr_field_find()` opens with `hdrtoken_is_wks(field_name.data())`, which is a pointer-range test against the well-known-string heap and never looks at the length. `FILTER_HEADERS` holds real WKS pointers, so the zero-length lookup still took the WKS-index path and found the field. Range detection worked in release. And `TSHandleMLocRelease()` returns `TS_SUCCESS` immediately for an `HTTP_HEADER` object, so releasing the header mloc frees nothing and nothing was leaking there.
   
   What is actually wrong, and what this change fixes:
   
   - a leaked `MIMEFieldSDKHandle` on every request carrying one of the six headers, because `TSMimeHdrFieldFind()` allocates a handle per hit and the boolean-context call discarded it. That one is real on any build, and it is the field handle, not the header handle.
   - a debug-build abort on `ink_assert(!field_name.empty())`, compiled out in release.
   
   I have also been precise in the description about what the new test proves: it discriminates on an assertion-enabled build, which is what AuTest and CI use, but it would pass against the unfixed plugin in a release build, since there the defect is the leak rather than a behaviour change. The runs still earn their place because they pin two options that had no coverage at all.
   
   The diff itself is unchanged and still correct. `10.2.x` and `10.1.x` both carry the bug; `9.2.x` does not ship this plugin.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org