plugin/cache: prefetch without holding a client connection#7944
Merged
Conversation
7a3534b to
b708c35
Compare
Contributor
Author
|
LMK if you want me to open an Issue to discuss the concrete proposal. I can also open the implementation PR so you can see concretely what I'm driving towards if that's helpful. |
newPrefetchResponseWriter previously captured the client's ResponseWriter and cached its RemoteAddr at construction time, noting that the connection might already be closed by the time the prefetch goroutine runs. The embedded writer remained reachable via the un-overridden interface methods (LocalAddr, Close, TsigStatus, TsigTimersOnly, Hijack). Nothing on the prefetch path calls those today, which is why this hasn't bitten, but that's luck rather than design. This makes the cache's ResponseWriter a complete dns.ResponseWriter on its own: the five previously-delegating methods get nil-safe overrides, and newPrefetchResponseWriter constructs a writer with no inner RW. doPrefetch and exists previously took a request.Request and re-derived do/cd via state.Do(), which traverses state.W. They now take the primitives directly from cw (where they already live) so state.W can be nil. Signed-off-by: Ryan Brewster <rpb@anthropic.com>
b708c35 to
b8e9bd2
Compare
yongtang
approved these changes
Mar 24, 2026
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.
1. Why is this pull request needed and what does it do?
newPrefetchResponseWritercurrently captures the client'sResponseWriterand does some work to ensure thatRemoteAddris safe even if the client's connection is closed by the time the prefetch goroutine runs.This PR more strongly decouples the
newPrefetchResponseWriterfrom the client.LocalAddr, etc), and if anyone happened to use those methods they'd potentially misbehave2. Which issues (if any) are related?
#7904
In particular, right now the cache plugin's
prefetchbehavior requires a client to make a request in order to trigger a pre-fetch. If there are a ton of client requests, it can end up firing a ton of prefetch requests.One solution to this problem is to de-duplicate the upstream fetches. That seems reasonable, but there are some tricky aspects of it.
Here what I'm proposing is that we allow actually decouple prefetching from client requests entirely. This PR does not make that change, it's just prep-work.
My intent here is for this PR to be easy to review, but also to lay the groundwork for a subsequent PR.
3. Which documentation changes (if any) need to be made?
this is a an internal refactor, I don't believe this requires any docs changes
4. Does this introduce a backward incompatible change or deprecation?
prefetchrequests no longer carry the triggering client's address (intentionally)Downstream plugins see a zero TCP addr. I don't think this is impactful (I couldn't find a plugin after cache that reads it) but...in theory this could be a breaking change? Seems unavoidable if I also want to initiate requests that don't have an associated clients.