]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix ns_statscounter_recursclients counting bug
authorAram Sargsyan <aram@isc.org>
Tue, 18 Oct 2022 08:54:04 +0000 (08:54 +0000)
committerArаm Sаrgsyаn <aram@isc.org>
Tue, 18 Oct 2022 10:38:04 +0000 (10:38 +0000)
The incrementing and decrementing of 'ns_statscounter_recursclients'
were not properly balanced: for example, it would be incremented for
a prefetch query but not decremented if the query failed.

This commit ensures that the recursion quota and the recursive clients
counter are always in sync with each other.

(cherry picked from commit 82991451b41793af201d070aba654c4ea89819cb)

lib/ns/client.c
lib/ns/query.c

index ce2f84cc4303205d3f1c9f929dbccb91b7ccd8f0..6bd5ddfdefb9c0d14683078dd23bfe132cda7dab 100644 (file)
@@ -242,10 +242,8 @@ ns_client_endrequest(ns_client_t *client) {
         */
        if (client->recursionquota != NULL) {
                isc_quota_detach(&client->recursionquota);
-               if (client->query.prefetch == NULL) {
-                       ns_stats_decrement(client->sctx->nsstats,
-                                          ns_statscounter_recursclients);
-               }
+               ns_stats_decrement(client->sctx->nsstats,
+                                  ns_statscounter_recursclients);
        }
 
        /*
index 98cfffe8c3646b409b696760b08e4063194a9286..43a0293d5d3e2614ff773bf8b3fdc9913fc3d534 100644 (file)
@@ -2486,11 +2486,10 @@ prefetch_done(isc_task_t *task, isc_event_t *event) {
         */
        if (client->recursionquota != NULL) {
                isc_quota_detach(&client->recursionquota);
+               ns_stats_decrement(client->sctx->nsstats,
+                                  ns_statscounter_recursclients);
        }
 
-       ns_stats_decrement(client->sctx->nsstats,
-                          ns_statscounter_recursclients);
-
        free_devent(client, &event, &devent);
        isc_nmhandle_detach(&client->prefetchhandle);
 }
@@ -2518,6 +2517,8 @@ query_prefetch(ns_client_t *client, dns_name_t *qname,
                                          &client->recursionquota);
                switch (result) {
                case ISC_R_SUCCESS:
+                       ns_stats_increment(client->sctx->nsstats,
+                                          ns_statscounter_recursclients);
                        break;
                case ISC_R_SOFTQUOTA:
                        isc_quota_detach(&client->recursionquota);
@@ -2527,9 +2528,6 @@ query_prefetch(ns_client_t *client, dns_name_t *qname,
                }
        }
 
-       ns_stats_increment(client->sctx->nsstats,
-                          ns_statscounter_recursclients);
-
        tmprdataset = ns_client_newrdataset(client);
        if (tmprdataset == NULL) {
                return;
@@ -2736,6 +2734,8 @@ query_rpzfetch(ns_client_t *client, dns_name_t *qname, dns_rdatatype_t type) {
                                          &client->recursionquota);
                switch (result) {
                case ISC_R_SUCCESS:
+                       ns_stats_increment(client->sctx->nsstats,
+                                          ns_statscounter_recursclients);
                        break;
                case ISC_R_SOFTQUOTA:
                        isc_quota_detach(&client->recursionquota);
@@ -2745,9 +2745,6 @@ query_rpzfetch(ns_client_t *client, dns_name_t *qname, dns_rdatatype_t type) {
                }
        }
 
-       ns_stats_increment(client->sctx->nsstats,
-                          ns_statscounter_recursclients);
-
        tmprdataset = ns_client_newrdataset(client);
        if (tmprdataset == NULL) {
                return;
@@ -6128,11 +6125,10 @@ fetch_callback(isc_task_t *task, isc_event_t *event) {
 
        if (client->recursionquota != NULL) {
                isc_quota_detach(&client->recursionquota);
+               ns_stats_decrement(client->sctx->nsstats,
+                                  ns_statscounter_recursclients);
        }
 
-       ns_stats_decrement(client->sctx->nsstats,
-                          ns_statscounter_recursclients);
-
        LOCK(&client->manager->reclock);
        if (ISC_LINK_LINKED(client, rlink)) {
                ISC_LIST_UNLINK(client->manager->recursing, client, rlink);
@@ -6285,6 +6281,11 @@ ns_query_recurse(ns_client_t *client, dns_rdatatype_t qtype, dns_name_t *qname,
        if (client->recursionquota == NULL) {
                result = isc_quota_attach(&client->sctx->recursionquota,
                                          &client->recursionquota);
+               if (result == ISC_R_SUCCESS || result == ISC_R_SOFTQUOTA) {
+                       ns_stats_increment(client->sctx->nsstats,
+                                          ns_statscounter_recursclients);
+               }
+
                if (result == ISC_R_SOFTQUOTA) {
                        isc_stdtime_t now;
                        isc_stdtime_get(&now);
@@ -6333,9 +6334,6 @@ ns_query_recurse(ns_client_t *client, dns_rdatatype_t qtype, dns_name_t *qname,
                ns_client_recursing(client);
        }
 
-       ns_stats_increment(client->sctx->nsstats,
-                          ns_statscounter_recursclients);
-
        /*
         * Invoke the resolver.
         */