You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
negative_revalidating_lifetime seems not respected #7425
CONFIG proxy.config.http.negative_revalidating_enabled INT 1
CONFIG proxy.config.http.negative_revalidating_lifetime INT 10
I have such scenario:
with executing GET /test HTTP/1.1 origin replies HTTP/1.1 200 OK with header: Cache-Control: max-age=11, public and some content, I see TCP_MISS/200 in squid.log, I am happy with the reply
then I configured origin to reply HTTP/1.1 503 Service Unavailable with cache-control: no-cache
did again GET /test HTTP/1.1, got proper 200 reply from cache, in squid.log I see TCP_REFRESH_MISS/200
sleep 15 (more then negative_revalidating_lifetime)
did again GET /test HTTP/1.1, got:
surprising 200 reply
expected: 503 code from the origin
in squid.log I see TCP_REFRESH_MISS/200
It happens with 7.1.11, 8.1.0 and 8.1.1.
Note: Same happens if origin is just down, where I'd expect 5xx code from trafficserver after waiting for enough of time.
@lukenowak According to the source code, ATS can return a stale cache if is_stale_cache_response_returnable() returns true, that refers proxy.config.http.cache.max_stale_age but does NOT refer proxy.config.http.negative_revalidating_lifetime.
How long, in seconds, to consider a stale cached document valid if proxy.config.http.negative_revalidating_enabled is enabled and Traffic Server receives a negative (5xx only) response from the origin server during revalidation.
As @fdiary pointed out, max_stale_age is used to check the age of cached contents.
sleep 15 (so it is 2 seconds more, > max-age < max_stale_age)
GET results with 200 from TrafficServer
sleep 15+2 (so it is > max_stale_age)
GET results with 502 from the origin, I see response being updated as max-age passes (due to patch)
In this case, TrafficServer simulates "stale-if-error", expected. max_stale_age is the switch to control the time frame of the feature.
Setting negative_revalidating_lifetime to some value impacts case of step 7 with Expires header becoming Date + negative_revalidating_lifetime, but in step 9 there is no more Expires header.
Case 4 - origin not available anymore, negative_revalidating_enabled = 1
sleep 15 (so it is 2 seconds more, > max-age < max_stale_age)
GET results with 200 from ATS with Warning: 111 ApacheTrafficServer/8.1.1
sleep 15+2 (so it is > max_stale_age)
GET results with 502 from the origin, I see response being updated as max-age passes (due to patch)
In this case, TrafficServer simulates "stale-if-error", expected. max_stale_age is the switch to control the time frame of the feature.
Setting negative_revalidating_lifetime to some value impacts nothing
Conclusion
So currently the documentation (in records.config) could state:
proxy.config.http.negative_revalidating_enabled
Add something like "proxy.config.http.cache.max_stale_age can be used to configure how long the stale response will be given for available backend returning 5xx response."
proxy.config.http.negative_revalidating_lifetime
"...during revalidation, by setting Expire: header to value of Date: + value of the option"
proxy.config.http.cache.max_stale_age
"...cannot be cached. Is enabled by proxy.config.http.negative_revalidating_enabled"
Well, I am not sure about this, maybe such documentation shall be kept in cache-basics as some kind of scenario, anyway this is how I understood and configure TrafficServer "negative revalidation" now.
I'm working on this and adding an AuTest. In case this is helpful to others, I'll make some initial observations.
My guess at the initial intention of this code was that setting the Expires header, observed earlier in this ticket, would set the freshness lifetime to the desired value. This doesn't work however, for at least three reasons:
First, the Expires header is set to the value of negative_revalidating_lifetimein the future from the current time:
If that actually was effective, then when proxy.config.http.negative_revalidating_enabled was enabled, every single cached response for a down server would always be considered fresh and served out of the cache because its Expires time would always be in the future. This is clearly not the intention. Rather, for this calculation to work, we'd want to set the Expires value to the time past the calculated age of the resource, not the offset from the current time.
The second reason this doesn't work is that, per RFC 7234 section 4.2.1, the max-age directive takes precedence over the Expires header field. Thus in all responses that has max-age, the Expires header would never even be inspected. Notice that @lukenowak 's examples all use max-age, and indeed most tests would because that's the easiest way to test freshness behavior. (Fixing this by setting the max-age directive, however, would not be a sufficient fix because of the following paragraph.)
Thirdly, by the time the Expires header is set in the code, we've already completed freshness calculations. Otherwise we wouldn't be in the code determining whether the stale response can be served. Recall that the negative revalidating feature influences behavior for stale cached responses in which the origin is unreachable. Thus at this point, setting the Expires header is too late to influence ATS's freshness calculation. We would have to set it then re-perform the freshness calculation. This is not done.
In order to make proxy.config.http.negative_revalidating_lifetime behave like it is documented, the three above issues would need to be addressed.
For the sake of completeness, if that were done, the intention is that things should work like this:
A client makes a request to a server which responds with some cacheable positive response, such as a 200 OK.
At a point in the future after the cached resource is stale, the client requests the resource.
ATS notices that the resource is stale and attempts to revalidate it against the origin.
The origin is either unreachable by ATS or it replies with some 5xx response.
ATS notices that proxy.config.http.negative_revalidating_enabled is enabled.
ATS recalculates the freshness of the resource using the adjusted freshness calculation as set in proxy.config.http.negative_revalidating_lifetime. If the resource is fresh enough given this adjustment, reply with it.
If, after this adjusted freshness calculation, the object is still stale, then ATS will respect max_stale_age. If its staleness is less than max_stale_age it will reply with it, otherwise it will return a 5xx response.
For now, with the bug described in this ticket, step 6 is broken and never results in the object's freshness being recalculated. Thus a user can only influence negative revalidating responses via max_stale_age.
Activity
lukenowak commentedon Jan 14, 2021
With:
I start to got 503 replies after waiting for
max-agetime to pass, so it seems generally the behaviour is impacted by enabling that option.fdiary commentedon Jan 14, 2021
@lukenowak According to the source code, ATS can return a stale cache if
is_stale_cache_response_returnable()returns true, that refersproxy.config.http.cache.max_stale_agebut does NOT referproxy.config.http.negative_revalidating_lifetime.https://github.com/apache/trafficserver/blob/8.1.1/proxy/http/HttpTransact.cc#L5741
But I am not sure the difference between the purposes of these two variables.
masaori335 commentedon Jan 15, 2021
Descriptions of these configs seem ambiguous when and which config should be used.
As @fdiary pointed out,
max_stale_ageis used to check the age of cached contents.trafficserver/proxy/http/HttpTransact.cc
Line 5925 in 08fe521
OTOH,
negative_revalidating_lifetimeis only used to set theExpiresheader of stale contents.trafficserver/proxy/http/HttpTransact.cc
Line 4350 in 08fe521
If we take the doc literary, it seems like we should refer to
negative_revalidating_lifetimetoo when thenegative_revalidatingis enabled.lukenowak commentedon Jan 18, 2021
I have some cases (note: I am using version patched with #7422)
Cases
Case 1 - origin returns 502, negative_revalidating_enabled = 0
negative_revalidating_enabled = 0negative_revalidating_lifetime = 0max_stale_age = 30max-age<max_stale_age)This case, TrafficServer does not simulate "stale-if-error", expected.
Setting
negative_revalidating_lifetimeto some value impacts nothing.Case 2 - origin not available anymore, negative_revalidating_enabled = 0
negative_revalidating_enabled = 0negative_revalidating_lifetime = 0max_stale_age = 30max-age<max_stale_age)max_stale_age)This case, TrafficServer simulates a bit "stale-if-error", but only when backend is down (replies nothing).
Setting
negative_revalidating_lifetimeto some value impacts nothing.Case 3 - origin returns 502, negative_revalidating_enabled = 1
negative_revalidating_enabled = 1negative_revalidating_lifetime = 0max_stale_age = 30max-age<max_stale_age)max_stale_age)In this case, TrafficServer simulates "stale-if-error", expected.
max_stale_ageis the switch to control the time frame of the feature.Setting
negative_revalidating_lifetimeto some value impacts case of step 7 withExpiresheader becomingDate + negative_revalidating_lifetime, but in step 9 there is no moreExpiresheader.Case 4 - origin not available anymore, negative_revalidating_enabled = 1
negative_revalidating_enabled = 1negative_revalidating_lifetime = 0max_stale_age = 30max-age<max_stale_age)max_stale_age)In this case, TrafficServer simulates "stale-if-error", expected.
max_stale_ageis the switch to control the time frame of the feature.Setting
negative_revalidating_lifetimeto some value impacts nothingConclusion
So currently the documentation (in records.config) could state:
proxy.config.http.negative_revalidating_enabledAdd something like "
proxy.config.http.cache.max_stale_agecan be used to configure how long the stale response will be given for available backend returning 5xx response."proxy.config.http.negative_revalidating_lifetime"...during revalidation, by setting Expire: header to value of Date: + value of the option"
proxy.config.http.cache.max_stale_age"...cannot be cached. Is enabled by
proxy.config.http.negative_revalidating_enabled"Well, I am not sure about this, maybe such documentation shall be kept in cache-basics as some kind of scenario, anyway this is how I understood and configure TrafficServer "negative revalidation" now.
bryancall commentedon Mar 11, 2021
@bneradt Can you please document this? Thank you.
bneradt commentedon Mar 23, 2021
I'm working on this and adding an AuTest. In case this is helpful to others, I'll make some initial observations.
My guess at the initial intention of this code was that setting the Expires header, observed earlier in this ticket, would set the freshness lifetime to the desired value. This doesn't work however, for at least three reasons:
First, the Expires header is set to the value of
negative_revalidating_lifetimein the future from the current time:trafficserver/proxy/http/HttpTransact.cc
Line 4350 in 08fe521
If that actually was effective, then when
proxy.config.http.negative_revalidating_enabledwas enabled, every single cached response for a down server would always be considered fresh and served out of the cache because its Expires time would always be in the future. This is clearly not the intention. Rather, for this calculation to work, we'd want to set the Expires value to the time past the calculated age of the resource, not the offset from the current time.The second reason this doesn't work is that, per RFC 7234 section 4.2.1, the max-age directive takes precedence over the Expires header field. Thus in all responses that has max-age, the Expires header would never even be inspected. Notice that @lukenowak 's examples all use max-age, and indeed most tests would because that's the easiest way to test freshness behavior. (Fixing this by setting the max-age directive, however, would not be a sufficient fix because of the following paragraph.)
Thirdly, by the time the Expires header is set in the code, we've already completed freshness calculations. Otherwise we wouldn't be in the code determining whether the stale response can be served. Recall that the negative revalidating feature influences behavior for stale cached responses in which the origin is unreachable. Thus at this point, setting the Expires header is too late to influence ATS's freshness calculation. We would have to set it then re-perform the freshness calculation. This is not done.
In order to make
proxy.config.http.negative_revalidating_lifetimebehave like it is documented, the three above issues would need to be addressed.For the sake of completeness, if that were done, the intention is that things should work like this:
proxy.config.http.negative_revalidating_enabledis enabled.proxy.config.http.negative_revalidating_lifetime. If the resource is fresh enough given this adjustment, reply with it.max_stale_age. If its staleness is less thanmax_stale_ageit will reply with it, otherwise it will return a 5xx response.For now, with the bug described in this ticket, step 6 is broken and never results in the object's freshness being recalculated. Thus a user can only influence negative revalidating responses via
max_stale_age.mlibbey commentedon Mar 23, 2021
Thanks Brian -- fwiw, I tried a bash script a long while back #3211 -- don't think it covered all your cases :)