]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MEDIUM: cache: build the secondary key on an unusable first entry
authorOlivier Houchard <ohouchard@haproxy.com>
Wed, 25 Nov 2026 17:57:22 +0000 (18:57 +0100)
committerOlivier Houchard <cognet@ci0.org>
Wed, 25 Nov 2026 17:46:31 +0000 (18:46 +0100)
With "process-vary on", http_action_req_cache_use() returns without
building the secondary key when the first entry found for the primary
key cannot be used, because it is expired, stripped to its early hints
or still being stored. The response is then not stored if it has a Vary
header, since the transaction has no secondary key, and the expired
entry is not removed either. So once the first variant of a resource has
expired, this resource is not cached anymore, until that entry gets
evicted.

Let's build the secondary key in this case too, as was done before
commit 25fcee5b0 ("MEDIUM: cache: emit early hints if configured to do
so"), where an expired first entry was not returned by get_entry(). This
was introduced in 3.5-dev3, no backport is needed.

src/cache.c

index 13e51b3e50de56d71639d541f77f4d6a088d863e..8b390a83081e70721ba2fb7c5be60d2edab69e9f 100644 (file)
@@ -2934,6 +2934,10 @@ enum act_return http_action_req_cache_use(struct act_rule *rule, struct proxy *p
                 * can't use the cache's entry and must forward the request to
                 * the server. */
                if (!res) {
+                       /* the secondary key is needed to store the response */
+                       if ((cache->flags & CACHE_CF_VARY_PROCESSING) &&
+                           !(txn->flags & TX_CACHE_HAS_SEC_KEY))
+                               http_request_prebuild_full_secondary_key(s);
                        return ACT_RET_CONT;
                } else if (!(res->flags & CACHE_EF_COMPLETE) || (res->flags & CACHE_EF_STRIPPED)) {
                        release_entry(cache_tree, res, 1);