From 926f0323b6df457cdc68d2526dbb16a08bb78ada Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Thu, 22 Dec 2022 13:48:33 +0000 Subject: [PATCH] Fix an ADB quota management error in the resolver Normally, when a 'resquery_t' object is created in fctx_query(), we call dns_adb_beginudpfetch() (which increases the ADB quota) only if it's a UDP query. Then, in fctx_cancelquery(), we call dns_adb_endudpfetch() to decreases back the ADB quota, again only if it's a UDP query. The problem is that a UDP query can become a TCP query, preventing the quota from adjusting back in fctx_cancelquery() later. Call dns_adb_beginudpfetch() also when switching the query type from UDP to TCP. (cherry picked from commit 53afe1f978c7c46d961a00d2149f333bf6f0b687) --- lib/dns/resolver.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c index 6f95acd9b2..1b6a8894e8 100644 --- a/lib/dns/resolver.c +++ b/lib/dns/resolver.c @@ -2633,7 +2633,16 @@ resquery_send(resquery_t *query) { hint = dns_adb_getudpsize(fctx->adb, query->addrinfo); } else if (tried->count >= 2U) { - query->options |= DNS_FETCHOPT_TCP; + if ((query->options & DNS_FETCHOPT_TCP) == 0) { + /* + * Inform the ADB that we're ending a + * UDP fetch, and turn the query into + * a TCP query. + */ + dns_adb_endudpfetch(fctx->adb, + query->addrinfo); + query->options |= DNS_FETCHOPT_TCP; + } } } }