Caching responses with "Vary" header
| Affects | Status | Importance | Assigned to | Milestone | |
|---|---|---|---|---|---|
| | Squid |
Fix Released
|
High
|
||
| | squid3 (Debian) |
Fix Released
|
Undecided
|
Unassigned | |
| | squid3 (Ubuntu) |
Medium
|
Unassigned | ||
| | Trusty |
Medium
|
Diogo Matsubara | ||
Bug Description
See the upstream bug report for more details [1], but it seems as though squid in trusty isn't caching any response which includes a vary header [2]. The upstream bug was fixed in 3.3.12 [3].
Steps to reproduce:
* Setup an application returning responses with "Vary: User-Agent"
* Add squid in front of an application server
* Make multiple requests to squid
Expected result:
* Second request is a Hit
Actual result:
* Second (and subsequent) requests are all misses.
Repeat without a Vary header and things are cached as expected. Note, I've only reproduced this with a specific setup (as in [2]), I've not yet reproduced with a simplified setup to be certain I'm seeing the upstream bug.
[1] http://
[2] http://
[3] http://
Related branches
- Sebastien Bacher: Needs Information on 2015-01-30
-
Diff: 88 lines (+68/-0)3 files modifieddebian/changelog (+7/-0)
debian/patches/91-caching-with-vary-3806.patch (+60/-0)
debian/patches/series (+1/-0)
|
|
#2 |
*** Bug 3799 has been marked as a duplicate of this bug. ***
|
|
#3 |
Created attachment 2854
Set body size 0 on the vary marker object
I am suspecting that the recent changes to cache max-size is related to this. The internal Vary marker object we use in the cache has no body but was specifying 'unknown' body length instead of none.
Please test this patch.
|
|
#4 |
(In reply to comment #2)
> Created attachment 2854 [details]
> Set body size 0 on the vary marker object
>
> I am suspecting that the recent changes to cache max-size is related to this.
> The internal Vary marker object we use in the cache has no body but was
> specifying 'unknown' body length instead of none.
> Please test this patch.
Just tried the patch on Squid 3.2 in the context of bug 3799 and it did not make any difference. Does it require a higher version of Squid?
|
|
#5 |
(In reply to comment #3)
> (In reply to comment #2)
> > Created attachment 2854 [details]
> > Set body size 0 on the vary marker object
> >
> > I am suspecting that the recent changes to cache max-size is related to this.
> > The internal Vary marker object we use in the cache has no body but was
> > specifying 'unknown' body length instead of none.
> > Please test this patch.
>
> Just tried the patch on Squid 3.2 in the context of bug 3799 and it did not
> make any difference. Does it require a higher version of Squid?
I also have tested with squid 3.3.3 and made no difference, what debugging can I turn on and logs to provide to help diagnose?
Thanks
Scott
|
|
#6 |
Please find my analysis on this issue.
Squid 3.2.1
I have tracked this down to the way hash keys are generated and retrieved for requests with vary header. If you go to the squid source code file src/store_
const cache_key *
storeKeyPublicB
{
static cache_key digest[
unsigned char m = (unsigned char) method.id();
const char *url = urlCanonical(
SquidMD5_CTX M;
SquidMD5Ini
SquidMD5Upd
SquidMD5Upd
if (request-
SquidMD5Update(&M, (unsigned char *) request-
SquidMD5Fin
return digest;
}
you can see that MD5-based keys are generated based on request method id, request URL, and request vary header. The problem seems to be that when hash keys are generated during retrieval, the vary header field is empty and therefore although the resource is cached it cannot be retrieved because of the incorrect hash key.
If you comment out two lines from above as follows:
//if (request-
//SquidMD5Updat
and recompile squid you will see that such resources get served from cache indicating that the culprit is the vary header.
The part of the code that seems to be generating the hash keys for retrieval is inside src/store.cc (around line 625):
StoreEntry *
storeGetPublicB
{
return Store::
}
Here the vary header of the http request object req is empty. Therefore storeKeyPublicB
An example test case is:
which has the vary header: “Vary:accept-
|
|
#7 |
I just want to report that this bug affects my client's e-commerce. I believe this is pretty serious: it's a common practice to compress js/css and "vary" header is mandatory in this case.
I'm unsure if wait for a fix or revert to 2.x version of squid.
Please, let me know if you plan to fix it asap.
|
|
#8 |
(In reply to comment #5)
> you can see that MD5-based keys are generated based on request method id,
> request URL, and request vary header. The problem seems to be that when hash
> keys are generated during retrieval, the vary header field is empty and
> therefore although the resource is cached it cannot be retrieved because of the
> incorrect hash key.
I am not intimately familiar with this code, but I think empty vary_headers are expected on the first lookup. Looking at request alone, Squid does not yet know what request headers are subject to Vary control. To know that, Squid needs to retrieve the "master object" from the cache, find Vary header information there, fill vary_headers based on that information, do a second lookup, and retrieve the matching response from the cache (if any). Only during that second lookup the vary_headers member will be filled.
If your test case exposes the bug, then somebody needs to find out why the "master object" is not found in the cache during the first lookup (the one with empty vary_headers). To do that, one needs to investigate whether that "master object" was cached in the first place (when the original Vary response was received) and, if it was cached, why it was purged later (if it was purged) or why it was stored using a different key (also resulting in a miss).
|
|
#9 |
(In reply to comment #7)
> (In reply to comment #5)
>
> > you can see that MD5-based keys are generated based on request method id,
> > request URL, and request vary header. The problem seems to be that when hash
> > keys are generated during retrieval, the vary header field is empty and
> > therefore although the resource is cached it cannot be retrieved because of the
> > incorrect hash key.
>
> I am not intimately familiar with this code, but I think empty vary_headers are
> expected on the first lookup. Looking at request alone, Squid does not yet know
> what request headers are subject to Vary control. To know that, Squid needs to
> retrieve the "master object" from the cache, find Vary header information
> there, fill vary_headers based on that information, do a second lookup, and
> retrieve the matching response from the cache (if any). Only during that second
> lookup the vary_headers member will be filled.
>
> If your test case exposes the bug, then somebody needs to find out why the
> "master object" is not found in the cache during the first lookup (the one with
> empty vary_headers). To do that, one needs to investigate whether that "master
> object" was cached in the first place (when the original Vary response was
> received) and, if it was cached, why it was purged later (if it was purged) or
> why it was stored using a different key (also resulting in a miss).
So we need couple cases:
1. request that has vary header in it(multi or single) and should have in the reply.
2. request that has a vary response in it without having one in the request.
3. request that has vary header in it(multi or single) and will not have vary header in the response.
The above cases will show how squid react in any situation that exists with vary headers on the request and response.
A vary header in the response should be equal to the request and if not still it should satisfy the request.
In the case which there is a vary header in the response but not in the request it should be ignored since HTTP should work by concept of "one request one response" and this is how a cache should cache the requests in http1.x.
if you do think of another cases put them here.
Eliezer
|
|
#10 |
Created attachment 2969
proposed temporary fix for trunk
This patch contains several Vary caching fixes that make Vary caching work in my limited trunk tests.
One of the fixes is temporary -- it disables Vary response caching in shared memory cache (other caches should still work with these fixes). The same temporary change may also remove excessive "Vary object loop!" warnings in cache.log for folks using a shared memory cache.
The same patch may apply to earlier Squid versions. If you want to experiment, try patching with --fuzz=20 (if needed) and see whether the patch applies and the patched code compiles.
|
|
#11 |
(In reply to comment #9)
> Created attachment 2969 [details]
> proposed temporary fix for trunk
The startWriting() piece seems to be the core bug here and this fixes it.
Applied to Squid-3 for further testing, absent any more progress this will be in 3.5.
| Changed in squid3 (Ubuntu): | |
| status: | New → Triaged |
| Changed in squid3 (Ubuntu Trusty): | |
| status: | New → Triaged |
| Changed in squid3 (Ubuntu): | |
| importance: | Undecided → Medium |
| Changed in squid3 (Ubuntu Trusty): | |
| importance: | Undecided → Medium |
| tags: | added: bitesize |
| Changed in squid: | |
| importance: | Unknown → High |
| status: | Unknown → Fix Released |
| Amos Jeffries (yadi) wrote : | #13 |
Debian Sid and Jesse package squid3 includes the fix for this bug. Please update the Ubuntu packages to match the upstream Debain repository.
| Changed in squid3 (Debian): | |
| status: | New → Fix Released |
| Robie Basak (racb) wrote : | #14 |
We're past feature freeze for Vivid now, so I can't just update to the latest any more, unless only bugfixes are involved or the release team grant an exception. If you can give me backported patches though, I can apply those. Otherwise a fix will need to wait until I can figure out backporting patches myself, or wait until Vivid is released.
| Michael Nelson (michael.nelson) wrote : Re: [Bug 1336742] Re: Caching responses with "Vary" header | #15 |
On Fri, Feb 27, 2015 at 1:27 AM, Robie Basak <email address hidden> wrote:
> We're past feature freeze for Vivid now, so I can't just update to the
> latest any more, unless only bugfixes are involved or the release team
> grant an exception. If you can give me backported patches though, I can
> apply those.
I backported the fix to trusty as per the attached branch.
| Oleg Strikov (strikov) wrote : | #16 |
I prepared a debdiff for vivid (attached) and currently looking for sponsorship.
My repro case can be found here: http://
The attachment "lp-1336742-
[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issue please contact him.]
| tags: | added: patch |
| Oleg Strikov (strikov) wrote : | #18 |
Updated package has been pushed to vivid-proposed.
Feel free to try it.
| Launchpad Janitor (janitor) wrote : | #19 |
This bug was fixed in the package squid3 - 3.3.8-1ubuntu12
---------------
squid3 (3.3.8-1ubuntu12) vivid; urgency=medium
* debian/
specific ones, and simplify the logic.
* debian/
of parsing cmdline; the latter has "(squid-1)" with the init.d script, and
it's not really what we are interested in.
-- Martin Pitt <email address hidden> Fri, 06 Mar 2015 12:10:59 +0100
| Changed in squid3 (Ubuntu): | |
| status: | Triaged → Fix Released |
| Rolf Leggewie (r0lf) wrote : | #20 |
| Brian Murray (brian-murray) wrote : | #21 |
I'll go ahead and sponsor this.
| Changed in squid3 (Ubuntu Trusty): | |
| assignee: | nobody → Brian Murray (brian-murray) |
| status: | Triaged → In Progress |
Hello Michael, or anyone else affected,
Accepted squid3 into trusty-proposed. The package will build now and be available at https:/
Please help us by testing this new package. See https:/
If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, and change the tag from verification-needed to verification-done. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-
Further information regarding the verification process can be found at https:/
| Changed in squid3 (Ubuntu Trusty): | |
| status: | In Progress → Fix Committed |
| tags: | added: verification-needed |
| Michael Nelson (michael.nelson) wrote : Re: [Bug 1336742] Re: Caching responses with "Vary" header | #23 |
On Wed, Jul 8, 2015 at 11:45 PM Chris J Arges <email address hidden>
wrote:
> Hello Michael, or anyone else affected,
>
>
Hi Chris,
Unfortunately I'm not able to reproduce the original problem with the
existing 3.3.8-1ubuntu6.2 (which is different to what I originally used) .
As I mentioned in the description, I'd not tested with a pristine trusty
environment, nor can I setup the same env with which I tested in the
original description.
In case I'm missing something obvious, and it helps someone else reproduce
the original issue and/or confirm the fix, here is how I tried to reproduce
the original problem just now on a freshly booted trusty instance:
http://
Of course, if we're unable to reproduce the original issue, it may have
been specific to something in the environment I had (or have others seen
the same?). One possibility is that the app server I was using was sending
an incorrect Content-Length when Vary was present (as I noticed that an
incorrect Content-Length header causes squid to not cache, which is
understandable).
| Robie Basak (racb) wrote : | #24 |
Diogo will take a look for us to see if we can drive this through.
| Changed in squid3 (Ubuntu Trusty): | |
| assignee: | Brian Murray (brian-murray) → Diogo Matsubara (matsubara) |
| Diogo Matsubara (matsubara) wrote : | #25 |
I verified the fix with Oleg's test case (comment #16). I first reproduced the issue in a pristine trusty environment with squid3 (3.3.8-1ubuntu6.2) and then installed the proposed package (3.3.8-1ubuntu6.3) and got a TCP_MEM_HIT/200 just like Oleg's example.
| tags: |
added: verification-done removed: verification-needed |
| Launchpad Janitor (janitor) wrote : | #26 |
This bug was fixed in the package squid3 - 3.3.8-1ubuntu6.3
---------------
squid3 (3.3.8-1ubuntu6.3) trusty-proposed; urgency=low
* d/patches/
for the bug which prevented squid from caching responses with
Vary header. (LP: #1336742) Based on work by Oleg Strikov.
-- Rolf Leggewie <email address hidden> Wed, 01 Jul 2015 15:25:59 -0700
| Changed in squid3 (Ubuntu Trusty): | |
| status: | Fix Committed → Fix Released |
The verification of the Stable Release Update for squid3 has completed successfully and the package has now been released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regressions.


When objects retrieved from web server return with a vary header, object is never cached and all future requests are always logged as a MISS.
Disabling the vary header on web server causes the same object to be cached as expected.
Seems to be same issues as discussed here : http:// www.squid- cache.org/ mail-archive/ squid-dev/ 201207/ 0100.html