]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Prevent duplicate StreamDNS read jobs
authorOndřej Surý <ondrej@sury.org>
Sat, 8 Aug 2026 05:24:26 +0000 (07:24 +0200)
committerOndřej Surý <ondrej@isc.org>
Sat, 8 Aug 2026 09:11:12 +0000 (11:11 +0200)
Coalesce repeated reads while an asynchronous StreamDNS job is pending.

lib/isc/netmgr/streamdns.c

index 9dd8b0aeab61808cd80df34ea5084458fa2c116f..170d5714d3387a2e944e379e73dabe559837965f 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <isc/async.h>
 #include <isc/atomic.h>
+#include <isc/log.h>
 #include <isc/result.h>
 #include <isc/thread.h>
 
@@ -888,6 +889,8 @@ streamdns_read_cb(void *arg) {
        REQUIRE(VALID_NMSOCK(sock));
        REQUIRE(sock->tid == isc_tid());
 
+       sock->processing = false;
+
        if (streamdns_closing(sock)) {
                streamdns_failed_read_cb(sock, ISC_R_CANCELED, false);
                goto detach;
@@ -925,6 +928,14 @@ isc__nm_streamdns_read(isc_nmhandle_t *handle, isc_nm_recv_cb_t cb,
                isc_nmhandle_attach(handle, &sock->recv_handle);
        }
 
+       /*
+        * Prevent scheduling the job or processing data if streamdns_read_cb
+        * has been already scheduled.
+        */
+       if (sock->processing) {
+               return;
+       }
+
        /*
         * In some cases there is little sense in making the operation
         * asynchronous as we just want to start reading from the
@@ -950,6 +961,7 @@ isc__nm_streamdns_read(isc_nmhandle_t *handle, isc_nm_recv_cb_t cb,
         */
 
        isc__nmsocket_attach(sock, &(isc_nmsocket_t *){ NULL });
+       sock->processing = true;
        isc_job_run(sock->worker->loop, &sock->job, streamdns_read_cb, sock);
 }