redo_cache_lookup: move to examples; fix fallback lifetime#13209
Open
bneradt wants to merge 1 commit into
Open
redo_cache_lookup: move to examples; fix fallback lifetime#13209bneradt wants to merge 1 commit into
fallback lifetime#13209bneradt wants to merge 1 commit into
Conversation
The redo_cache_lookup plugin kept the fallback URL as a pointer into the plugin.config argv storage. That storage can be released after plugin initialization, leaving cache-lookup-complete callbacks to dereference stale memory. This copies the parsed fallback URL into plugin-owned storage and passes its owned bytes to TSHttpTxnRedoCacheLookup. Also, while investigating this, it looks like this plugin was made simply to demonstrate the use of TSHttpTxnRedoCacheLookup rather than being a production-useful plugin. The initial commit says as much and there is no customer-facing documentation for this plugin. As such, I'm moving this to the examples plugin.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a lifetime bug in the redo_cache_lookup plugin by moving fallback URL storage into plugin-owned memory (avoiding pointers into plugin.config argv storage), and rehomes the plugin from plugins/experimental/ to example/plugins/c-api/ as an example of using TSHttpTxnRedoCacheLookup.
Changes:
- Moved
redo_cache_lookupfrom experimental plugins to the C-API examples and removed the experimental build option. - Copied the configured
--fallbackURL into owned storage and used it when callingTSHttpTxnRedoCacheLookup. - Added Catch2 unit tests for configuration parsing to ensure the fallback URL is copied.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| plugins/experimental/redo_cache_lookup/redo_cache_lookup.cc | Removed the experimental plugin implementation (now moved to examples). |
| plugins/experimental/redo_cache_lookup/README.md | Removed experimental plugin README (superseded by example readme). |
| plugins/experimental/redo_cache_lookup/CMakeLists.txt | Removed experimental plugin build definition. |
| plugins/experimental/CMakeLists.txt | Stopped including the removed experimental plugin directory. |
| cmake/ExperimentalPlugins.cmake | Removed BUILD_REDO_CACHE_LOOKUP option. |
| example/plugins/c-api/redo_cache_lookup/redo_cache_lookup.cc | New example plugin using C API and plugin-owned fallback storage. |
| example/plugins/c-api/redo_cache_lookup/redo_cache_lookup_config.h | Added config parsing helper for --fallback / -f. |
| example/plugins/c-api/redo_cache_lookup/readme.txt | Added example usage documentation. |
| example/plugins/c-api/redo_cache_lookup/unit_tests/test_redo_cache_lookup_config.cc | Added unit tests verifying fallback URL parsing/copy semantics. |
| example/plugins/c-api/CMakeLists.txt | Builds the new example plugin and its unit test under BUILD_TESTING. |
Comment on lines
+53
to
+57
| if (TSHttpTxnCacheLookupStatusGet(txnp, &status) != TS_SUCCESS || status == TS_CACHE_LOOKUP_MISS || | ||
| status == TS_CACHE_LOOKUP_SKIPPED) { | ||
| Dbg(dbg_ctl, "rewinding to check for fallback url: %s", config->fallback.c_str()); | ||
| TSHttpTxnRedoCacheLookup(txnp, config->fallback.c_str(), static_cast<int>(config->fallback.size())); | ||
| } |
Comment on lines
+88
to
+89
| TSCont contp = TSContCreate(handle_cache_lookup_complete, nullptr); | ||
| TSContDataSet(contp, new RedoCacheLookupConfig(*fallback)); |
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.
The redo_cache_lookup plugin kept the fallback URL as a pointer into the plugin.config argv storage. That storage can be released after plugin initialization, leaving cache-lookup-complete callbacks to dereference stale memory.
This copies the parsed fallback URL into plugin-owned storage and passes its owned bytes to TSHttpTxnRedoCacheLookup.
Also, while investigating this, it looks like this plugin was made simply to demonstrate the use of TSHttpTxnRedoCacheLookup rather than being a production-useful plugin. The initial commit says as much and there is no customer-facing documentation for this plugin. As such, I'm moving this to the examples plugin.