fix: usr: Fix shutdown INSIST in dns_dispatchmgr_getblackhole

Previously, `named` could trigger an assertion in `dns_dispatchmgr_getblackhole`
while shutting down. This has been fixed.

Closes #5525

Merge branch '5525-attach-to-dispatchmgr-to-fctx' into 'main'

See merge request isc-projects/bind9!11131
This commit is contained in:
Mark Andrews 2025-10-28 09:37:00 +11:00
commit 8c009d31ae

View file

@ -266,7 +266,6 @@ typedef struct query {
isc_refcount_t references;
fetchctx_t *fctx;
dns_message_t *rmessage;
dns_dispatchmgr_t *dispatchmgr;
dns_dispatch_t *dispatch;
dns_adbaddrinfo_t *addrinfo;
isc_time_t start;
@ -396,6 +395,7 @@ struct fetchctx {
ISC_LIST(dns_validator_t) validators;
dns_db_t *cache;
dns_adb_t *adb;
dns_dispatchmgr_t *dispatchmgr;
bool ns_ttl_ok;
uint32_t ns_ttl;
isc_counter_t *qc;
@ -2041,7 +2041,6 @@ fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo,
*query = (resquery_t){
.options = options,
.addrinfo = addrinfo,
.dispatchmgr = res->view->dispatchmgr,
.link = ISC_LINK_INITIALIZER,
};
@ -2090,7 +2089,7 @@ fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo,
}
isc_sockaddr_setport(&addr, 0);
result = dns_dispatch_createtcp(res->view->dispatchmgr, &addr,
result = dns_dispatch_createtcp(fctx->dispatchmgr, &addr,
&sockaddr, addrinfo->transport,
DNS_DISPATCHOPT_UNSHARED,
&query->dispatch);
@ -2101,9 +2100,8 @@ fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo,
FCTXTRACE("connecting via TCP");
} else {
if (have_addr) {
result = dns_dispatch_createudp(res->view->dispatchmgr,
&addr,
&query->dispatch);
result = dns_dispatch_createudp(
fctx->dispatchmgr, &addr, &query->dispatch);
if (result != ISC_R_SUCCESS) {
goto cleanup_query;
}
@ -3744,7 +3742,7 @@ possibly_mark(fetchctx_t *fctx, dns_adbaddrinfo_t *addr) {
const char *msg = NULL;
isc_netaddr_fromsockaddr(&ipaddr, sa);
blackhole = dns_dispatchmgr_getblackhole(res->view->dispatchmgr);
blackhole = dns_dispatchmgr_getblackhole(fctx->dispatchmgr);
(void)dns_peerlist_peerbyaddr(res->view->peers, &ipaddr, &peer);
if (blackhole != NULL) {
@ -4469,6 +4467,7 @@ fctx_destroy(fetchctx_t *fctx) {
}
dns_db_detach(&fctx->cache);
dns_adb_detach(&fctx->adb);
dns_dispatchmgr_detach(&fctx->dispatchmgr);
dns_resolver_detach(&fctx->res);
@ -4867,10 +4866,19 @@ fctx_create(dns_resolver_t *res, isc_loop_t *loop, const dns_name_t *name,
isc_interval_set(&fctx->interval, 2, 0);
/*
* Attach to the view's cache and adb.
* Attach to the view's adb, dispatchmgr and cache adb.
*/
dns_db_attach(res->view->cachedb, &fctx->cache);
dns_view_getadb(res->view, &fctx->adb);
if (fctx->adb == NULL) {
result = ISC_R_SHUTTINGDOWN;
goto cleanup_qmessage;
}
fctx->dispatchmgr = dns_view_getdispatchmgr(res->view);
if (fctx->dispatchmgr == NULL) {
result = ISC_R_SHUTTINGDOWN;
goto cleanup_adb;
}
dns_db_attach(res->view->cachedb, &fctx->cache);
ISC_LIST_INIT(fctx->resps);
fctx->magic = FCTX_MAGIC;
@ -4894,6 +4902,9 @@ fctx_create(dns_resolver_t *res, isc_loop_t *loop, const dns_name_t *name,
return ISC_R_SUCCESS;
cleanup_adb:
dns_adb_detach(&fctx->adb);
cleanup_qmessage:
dns_message_detach(&fctx->qmessage);