2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 14:35:26 +00:00

Attach to separate recursion quota pointers

Similarly to how different code paths reused common client handle
pointers and fetch references despite being logically unrelated, they
also reuse client->recursionquota, the field in which a reference to the
recursion quota is stored.  This unnecessarily forces all code using
that field to be aware of the fact that it is overloaded by different
features.

Overloading client->recursionquota also causes inconsistent behavior.
For example, if prefetch code triggers recursion and then delegation
handling code also triggers recursion, only one of these code paths will
be able to attach to the recursion quota, but both recursions will be
started anyway.  In other words, each code path only checks whether the
recursion quota has not been exceeded if the quota has not yet been
attached to by another code path.  This behavior theoretically allows
the configured recursion quota to be slightly exceeded; while it is not
expected to be a real-world operational issue, it is still confusing and
should therefore be fixed.

Extend the structures comprising the 'recursions' array with a new field
holding a pointer to the recursion quota that a given recursion process
attached to.  Update all code paths using client->recursionquota so that
they use the appropriate slot in the 'recursions' array.  Drop the
'recursionquota' field from ns_client_t.
This commit is contained in:
Michał Kępień
2022-06-14 13:13:32 +02:00
parent a4e92e3d0c
commit 172e15f7ad
5 changed files with 54 additions and 34 deletions

View File

@@ -62,7 +62,6 @@
#include <ns/interfacemgr.h>
#include <ns/log.h>
#include <ns/notify.h>
#include <ns/query.h>
#include <ns/server.h>
#include <ns/stats.h>
#include <ns/update.h>
@@ -268,9 +267,9 @@ ns_client_endrequest(ns_client_t *client) {
* fetch_callback(), but if we're shutting down and canceling then
* it might not have happened.
*/
if (client->recursionquota != NULL) {
isc_quota_detach(&client->recursionquota);
if (FETCH_RECTYPE_PREFETCH(client) == NULL) {
for (int i = 0; i < RECTYPE_COUNT; i++) {
if (client->query.recursions[i].quota != NULL) {
isc_quota_detach(&client->query.recursions[i].quota);
ns_stats_decrement(client->manager->sctx->nsstats,
ns_statscounter_recursclients);
}
@@ -1647,7 +1646,9 @@ ns__client_reset_cb(void *client0) {
}
client->state = NS_CLIENTSTATE_READY;
INSIST(client->recursionquota == NULL);
for (int i = 0; i < RECTYPE_COUNT; i++) {
INSIST(client->query.recursions[i].quota == NULL);
}
#ifdef WANT_SINGLETRACE
isc_log_setforcelog(false);
@@ -1763,7 +1764,9 @@ ns__client_request(isc_nmhandle_t *handle, isc_result_t eresult,
client->attributes |= NS_CLIENTATTR_TCP;
}
INSIST(client->recursionquota == NULL);
for (int i = 0; i < RECTYPE_COUNT; i++) {
INSIST(client->query.recursions[i].quota == NULL);
}
INSIST(client->state == NS_CLIENTSTATE_READY);