From ea301cf06236b87f6811cd1352fe3b7bc097961b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Wed, 15 Jan 2025 13:02:20 +0100 Subject: [PATCH] Shutdown the fetch context after canceling the last fetch Currently, the fetch context will continue running even when the last fetch (response) has been removed from the context, so named can process and cache the answer. This can lead to a situation where the number of outgoing recursing clients exceeds the the configured number for recursive-clients. Be more stringent about the recursive-clients limit and shutdown the fetch context immediately after the last fetch has been canceled from that particular fetch context. (cherry picked from commit 9f945c8b67006a1e495373eacb917ec2c47200d6) --- lib/dns/resolver.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c index 5a537145f6..75d8e88bac 100644 --- a/lib/dns/resolver.c +++ b/lib/dns/resolver.c @@ -10604,6 +10604,7 @@ fail: void dns_resolver_cancelfetch(dns_fetch_t *fetch) { fetchctx_t *fctx = NULL; + bool last_fetch = false; REQUIRE(DNS_FETCH_VALID(fetch)); fctx = fetch->private; @@ -10634,11 +10635,15 @@ dns_resolver_cancelfetch(dns_fetch_t *fetch) { } } - /* - * The fctx continues running even if no fetches remain; - * the answer is still cached. - */ + if (ISC_LIST_EMPTY(fctx->resps)) { + last_fetch = true; + } UNLOCK(&fctx->lock); + + if (last_fetch) { + fetchctx_ref(fctx); + isc_async_run(fctx->loop, fctx_shutdown, fctx); + } } void