Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions proxy/http/HttpTransact.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,13 @@ HttpTransact::OSDNSLookup(State *s)
} else {
TxnDebug("http_seq", "[HttpTransact::OSDNSLookup] DNS Lookup unsuccessful");

// Even with unsuccessful DNS lookup, return stale object from cache if applicable
if (is_cache_hit(s->cache_lookup_result) && is_stale_cache_response_returnable(s)) {
s->source = SOURCE_CACHE;
TxnDebug("http_trans", "[hscno] serving stale doc to client");
build_response_from_cache(s, HTTP_WARNING_CODE_REVALIDATION_FAILED);
return;
}
// output the DNS failure error message
SET_VIA_STRING(VIA_DETAIL_TUNNEL, VIA_DETAIL_TUNNEL_NO_FORWARD);
// Set to internal server error so later logging will pick up SQUID_LOG_ERR_DNS_FAIL
Expand Down Expand Up @@ -2669,16 +2676,7 @@ HttpTransact::HandleCacheOpenReadHitFreshness(State *s)
SET_VIA_STRING(VIA_CACHE_RESULT, VIA_IN_CACHE_STALE);
}

if (!s->force_dns) { // If DNS is not performed before
if (need_to_revalidate(s)) {
TRANSACT_RETURN(SM_ACTION_API_CACHE_LOOKUP_COMPLETE,
CallOSDNSLookup); // content needs to be revalidated and we did not perform a dns ....calling DNS lookup
} else { // document can be served can cache
TRANSACT_RETURN(SM_ACTION_API_CACHE_LOOKUP_COMPLETE, HttpTransact::HandleCacheOpenReadHit);
}
} else { // we have done dns . Its up to HandleCacheOpenReadHit to decide to go OS or serve from cache
TRANSACT_RETURN(SM_ACTION_API_CACHE_LOOKUP_COMPLETE, HttpTransact::HandleCacheOpenReadHit);
}
TRANSACT_RETURN(SM_ACTION_API_CACHE_LOOKUP_COMPLETE, HttpTransact::HandleCacheOpenReadHit);
}

///////////////////////////////////////////////////////////////////////////////
Expand Down
57 changes: 57 additions & 0 deletions tests/gold_tests/proxy_protocol/gold/serve_stale_dns_fail.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
``
> GET / HTTP/1.1
> Host: ``
> User-Agent: curl/``
> Accept: */*
``
< HTTP/1.1 200 OK
< Server: ATS``
< Accept-Ranges: bytes
< Content-Length: 6
< Cache-Control: public, max-age=5
< Expires: ``
< Age: ``
< Date: ``
< Connection: keep-alive
``
> GET / HTTP/1.1
> Host: ``
> User-Agent: curl/``
> Accept: */*
``
< HTTP/1.1 500 Cannot find server.
< Date: ``
< Server: ATS``
< Cache-Control: no-store
< Content-Type: ``
< Content-Language: ``
< Content-Length: ``
< Connection: keep-alive
``
> GET / HTTP/1.1
> Host: ``
> User-Agent: curl/``
> Accept: */*
``
< HTTP/1.1 200 OK
< Server: ATS``
< Accept-Ranges: bytes
< Content-Length: 6
< Cache-Control: public, max-age=5
< Age: ``
< Date: ``
< Connection: keep-alive
``
> GET / HTTP/1.1
> Host: ``
> User-Agent: curl/``
> Accept: */*
``
< HTTP/1.1 500 Cannot find server.
< Date: ``
< Server: ATS``
< Cache-Control: no-store
< Content-Type: ``
< Content-Language: ``
< Content-Length: ``
``
79 changes: 79 additions & 0 deletions tests/gold_tests/proxy_protocol/proxy_serve_stale_dns_fail.test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
'''
Test proxy serving stale content when DNS lookup fails
'''
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

Test.ContinueOnFail = True
# Set up hierarchical caching processes
ts_child = Test.MakeATSProcess("ts_child")
ts_parent = Test.MakeATSProcess("ts_parent")
server_name = "http://unknown.domain.com/"

Test.testName = "STALE"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of our Au tests don't assigned testName, I'm not sure what it's for:

wkaras ~/REPOS/TS3/tests/gold_tests
M$ find . -name \*.test.py | wc -l
     239
wkaras ~/REPOS/TS3/tests/gold_tests
M$ fgrep Test.testName $( find . -name \*.test.py ) | wc -l
      44
wkaras ~/REPOS/TS3/tests/gold_tests
M$


# Config child proxy to route to parent proxy
ts_child.Disk.records_config.update({
'proxy.config.url_remap.pristine_host_hdr': 1,
'proxy.config.http.cache.max_stale_age': 10,
'proxy.config.http.parent_proxy.self_detect': 0,
})
ts_child.Disk.parent_config.AddLine(
f'dest_domain=. parent=localhost:{ts_parent.Variables.port} round_robin=consistent_hash go_direct=false'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So even with this configured, child TS will still do a DNS lookup on unkown.domain.com ? Did you see the DNS lookup in the http debug trace output?

Copy link
Contributor Author

@serrislew serrislew Dec 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The http debug trace output shows the child doing PPDNS lookup to the parent and the parent doing a DNS lookup to unknown.domain.com (OS). After the DNS lookup fails for the parent but the parent has the stale returnable object in its cache, the child will revalidate from the parent (without doing a DNS lookup) and return the object to the client. Let me know if you are seeing something different in the debug trace output!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lately we've been including DNS servers in our Au tests:

'proxy.config.dns.nameservers': f"127.0.0.1:{dns.Variables.Port}", # Only nameservers if resolv_conf NULL.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why ATS would do a DNS lookup on the request host when it's not using the request host as the next hop. But I suppose that's beyond the scope of this PR.

)
ts_child.Disk.remap_config.AddLine(
f'map http://localhost:{ts_child.Variables.port} {server_name}'
)

# Configure parent proxy
ts_parent.Disk.records_config.update({
'proxy.config.url_remap.pristine_host_hdr': 1,
'proxy.config.http.cache.max_stale_age': 10,
})
ts_parent.Disk.remap_config.AddLine(
f'map http://localhost:{ts_parent.Variables.port} {server_name}'
)
ts_parent.Disk.remap_config.AddLine(
f'map {server_name} {server_name}'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am testing for non-hierarchical scenarios as well so the ts_parent server is mapped to the OS and gets called directly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively you can also do:

'proxy.config.url_remap.remap_required': 0,

But the way you have it is fine.

)

# Object to push to proxies
stale_5 = "HTTP/1.1 200 OK\nServer: ATS/10.0.0\nAccept-Ranges: bytes\nContent-Length: 6\nCache-Control: public, max-age=5\n\nCACHED"
stale_10 = "HTTP/1.1 200 OK\nServer: ATS/10.0.0\nAccept-Ranges: bytes\nContent-Length: 6\nCache-Control: public, max-age=10\n\nCACHED"


# Testing scenarios
child_curl_request = (
# Test child serving stale with failed DNS OS lookup
f'curl -X PUSH -d "{stale_5}" "http://localhost:{ts_child.Variables.port}";'
f'curl -X PUSH -d "{stale_10}" "http://localhost:{ts_parent.Variables.port}";'
f'sleep 7; curl -s -v http://localhost:{ts_child.Variables.port};'
f'sleep 15; curl -s -v http://localhost:{ts_child.Variables.port};'
# Test parent serving stale with failed DNS OS lookup
f'curl -X PUSH -d "{stale_5}" "http://localhost:{ts_parent.Variables.port}";'
f'sleep 7; curl -s -v http://localhost:{ts_parent.Variables.port};'
f'sleep 15; curl -s -v http://localhost:{ts_parent.Variables.port};'
)

# Test case for when parent server is down but child proxy can serve cache object
tr = Test.AddTestRun()
tr.Processes.Default.Command = child_curl_request
tr.Processes.Default.ReturnCode = 0
tr.Processes.Default.StartBefore(ts_child)
tr.Processes.Default.StartBefore(ts_parent)
tr.Processes.Default.Streams.stderr = "gold/serve_stale_dns_fail.gold"
tr.StillRunningAfter = ts_child
tr.StillRunningAfter = ts_parent