]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Test resolver statistics when responses time out
authorAram Sargsyan <aram@isc.org>
Thu, 6 Mar 2025 14:37:09 +0000 (14:37 +0000)
committerAram Sargsyan <aram@isc.org>
Mon, 31 Mar 2025 19:06:42 +0000 (19:06 +0000)
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)

bin/tests/system/resolver/ans3/ans.pl
bin/tests/system/resolver/tests.sh
bin/tests/system/resolver/tests_sh_resolver.py

index 880848e9c293123bb403645540e7bd66d6add4a3..f9690dda2aeb2a6652930411f22919856ddc8bdf 100644 (file)
@@ -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;
index 23b42f728cd9166c2053e1a90e274ff418fe694b..2864aae9501778491bf67d7a678c1bbfaa1e8628 100755 (executable)
@@ -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.
index 4677a8337e0f9afabd691b923a6dbda9cda07cdc..2362ae172601349ff80295afe2fe1cb62b299b77 100644 (file)
@@ -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*",