fix: dev: Attach socket before async streamdns_resume_processing

Call to `streamdns_resume_processing` is asynchronous but the socket
passed as argument is not attached when scheduling the call.

While there is no reproducible way (so far) to make the socket reference
number down to 0 before `streamdns_resume_processing` is called, attach
the socket before scheduling the call. This guard against an hypothetic
case where, for some reasons, the socket refcount would reach 0, and be
freed from memory when `streamdns_resume_processing` is called.

Closes #5620

Merge branch '5620-attach-socket-streamdns_resume_processing' into 'main'

See merge request isc-projects/bind9!11247
This commit is contained in:
Colin Vidal 2025-11-20 18:52:29 +01:00
commit fec55d786a

View file

@ -93,6 +93,8 @@ streamdns_closing(isc_nmsocket_t *sock);
static void
streamdns_resume_processing(void *arg);
static void
async_streamdns_resume_processing(void *arg);
static void
streamdns_resumeread(isc_nmsocket_t *sock, isc_nmhandle_t *transphandle) {
@ -193,8 +195,9 @@ streamdns_on_complete_dnsmessage(isc_dnsstream_assembler_t *dnsasm,
* Process more DNS messages in the next loop tick.
*/
streamdns_pauseread(sock, transphandle);
isc_async_run(sock->worker->loop, streamdns_resume_processing,
sock);
isc__nmsocket_attach(sock, &(isc_nmsocket_t *){ NULL });
isc_async_run(sock->worker->loop,
async_streamdns_resume_processing, sock);
}
return false;
@ -690,6 +693,15 @@ streamdns_resume_processing(void *arg) {
streamdns_handle_incoming_data(sock, sock->outerhandle, NULL, 0);
}
static void
async_streamdns_resume_processing(void *arg) {
isc_nmsocket_t *sock = (isc_nmsocket_t *)arg;
streamdns_resume_processing(sock);
isc__nmsocket_detach(&sock);
}
static isc_result_t
streamdns_accept_cb(isc_nmhandle_t *handle, isc_result_t result, void *cbarg) {
isc_nmsocket_t *listensock = (isc_nmsocket_t *)cbarg;