From: Aram Sargsyan Date: Thu, 6 Mar 2025 14:37:09 +0000 (+0000) Subject: Test resolver statistics when responses time out X-Git-Tag: v9.18.36~7^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=006130a35c219957b8a799e2c99f36ff746ad253;p=thirdparty%2Fbind9.git Test resolver statistics when responses time out Add a test to check that the timed out responses do not skew the normal responses statistics counters, and that they do update the timeouts counter. (cherry picked from commit 0c7fa8d572bf3e742a627ff660175683e131908b) --- diff --git a/bin/tests/system/resolver/ans3/ans.pl b/bin/tests/system/resolver/ans3/ans.pl index 880848e9c29..f9690dda2ae 100644 --- a/bin/tests/system/resolver/ans3/ans.pl +++ b/bin/tests/system/resolver/ans3/ans.pl @@ -74,6 +74,10 @@ sub handleQuery { $packet->push("answer", new Net::DNS::RR($qname . " 300 A 10.53.0.3")); } elsif ($qname eq "nodata.example.net") { # Do not add a SOA RRset. + } elsif ($qname eq "noresponse.example.net") { + # Do not response. + print "RESPONSE:\n"; + return ""; } elsif ($qname eq "nxdomain.example.net") { # Do not add a SOA RRset. $packet->header->rcode(NXDOMAIN); @@ -185,8 +189,12 @@ for (;;) { print "TCP request\n"; my $result = handleQuery($buf); $len = length($result); - $conn->syswrite(pack("n", $len), 2); - $n = $conn->syswrite($result, $len); + if ($len != 0) { + $conn->syswrite(pack("n", $len), 2); + $n = $conn->syswrite($result, $len); + } else { + $n = 0; + } print " Sent: $n chars via TCP\n"; } $conn->close; diff --git a/bin/tests/system/resolver/tests.sh b/bin/tests/system/resolver/tests.sh index 23b42f728cd..2864aae9501 100755 --- a/bin/tests/system/resolver/tests.sh +++ b/bin/tests/system/resolver/tests.sh @@ -85,6 +85,37 @@ if [ -x "${RESOLVE}" ]; then status=$((status + ret)) fi +rndccmd 10.53.0.1 stats || ret=1 # Get the responses, RTT and timeout statistics before the following timeout tests +grep -F 'responses received' ns1/named.stats >ns1/named.stats.responses-before || true +grep -F 'queries with RTT' ns1/named.stats >ns1/named.stats.rtt-before || true +grep -F 'query timeouts' ns1/named.stats >ns1/named.stats.timeouts-before || true +mv ns1/named.stats ns1/named.stats-before + +# Checking if the "hung fetch" timer kicks in and interrupts a non-responsive query. +n=$((n + 1)) +echo_i "checking no response timeout handling ($n)" +ret=0 +dig_with_opts +tcp +tries=1 +timeout=15 noresponse.example.net @10.53.0.1 a >dig.out.ns1.test${n} || ret=1 +grep -F "status: SERVFAIL" dig.out.ns1.test${n} >/dev/null || ret=1 +if [ $ret != 0 ]; then echo_i "failed"; fi +status=$((status + ret)) + +n=$((n + 1)) +echo_i "checking that the timeout didn't skew the resolver responses counters and did update the timeout counter ($n)" +ret=0 +rndccmd 10.53.0.1 stats || ret=1 +grep -F 'responses received' ns1/named.stats >ns1/named.stats.responses-after || true +grep -F 'queries with RTT' ns1/named.stats >ns1/named.stats.rtt-after || true +grep -F 'query timeouts' ns1/named.stats >ns1/named.stats.timeouts-after || true +mv ns1/named.stats ns1/named.stats-after +diff ns1/named.stats.responses-before ns1/named.stats.responses-after >/dev/null || ret=1 +diff ns1/named.stats.rtt-before ns1/named.stats.rtt-after >/dev/null || ret=1 +# The following check is disabled in this branch, because TCP timeouts don't +# work well here, and instead the "hung fetch" timer interrupts the query. +#diff ns1/named.stats.timeouts-before ns1/named.stats.timeouts-after >/dev/null && ret=1 +if [ $ret != 0 ]; then echo_i "failed"; fi +status=$((status + ret)) + n=$((n + 1)) echo_i "checking handling of bogus referrals ($n)" # If the server has the "INSIST(!external)" bug, this query will kill it. diff --git a/bin/tests/system/resolver/tests_sh_resolver.py b/bin/tests/system/resolver/tests_sh_resolver.py index 4677a8337e0..2362ae17260 100644 --- a/bin/tests/system/resolver/tests_sh_resolver.py +++ b/bin/tests/system/resolver/tests_sh_resolver.py @@ -22,6 +22,7 @@ pytestmark = pytest.mark.extra_artifacts( "resolve.out.*", "ans*/ans.run", "ans*/query.log", + "ns1/named.stats*", "ns4/tld.db", "ns5/trusted.conf", "ns6/K*",