fix: dev: Fix resquery reference imbalance on TCP connect failure

In fctx_query(), resquery_ref(query) is called before
dns_dispatch_connect() in anticipation of the resquery_connected()
callback consuming the reference.  When dns_dispatch_connect() fails
synchronously on TCP (e.g. from dns_transport_get_tlsctx() failing
in tcp_dispatch_connect()), the connect callback is never scheduled,
so the extra reference is never consumed.  This has been fixed.

Merge branch 'ondrej/fix-resquery-refcount' into 'main'

See merge request isc-projects/bind9!11640
This commit is contained in:
Ondřej Surý 2026-03-10 18:38:37 +01:00
commit 7c82cb0f14
2 changed files with 4 additions and 3 deletions

View file

@ -67,8 +67,8 @@ struct dns_dispatchmgr {
in_port_t *v4ports; /*%< available ports for IPv4 */
unsigned int nv4ports; /*%< # of available ports for IPv4 */
in_port_t *v6ports; /*%< available ports for IPv4 */
unsigned int nv6ports; /*%< # of available ports for IPv4 */
in_port_t *v6ports; /*%< available ports for IPv6 */
unsigned int nv6ports; /*%< # of available ports for IPv6 */
};
typedef enum {

View file

@ -2284,10 +2284,11 @@ fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo,
isc_log_write(
DNS_LOGCATEGORY_RESOLVER,
DNS_LOGMODULE_RESOLVER, log_level,
"Unable to establish a connection to %s: %s\n",
"Unable to establish a connection to %s: %s",
peerbuf, isc_result_totext(result));
}
dns_dispatch_done(&query->dispentry);
resquery_unref(query);
goto cleanup_fetch;
} else {
RUNTIME_CHECK(result == ISC_R_SUCCESS);