]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Run closehandle_cb on run queue instead of async queue
authorOndřej Surý <ondrej@isc.org>
Sun, 9 Apr 2023 04:48:46 +0000 (06:48 +0200)
committerOndřej Surý <ondrej@isc.org>
Wed, 12 Apr 2023 12:10:37 +0000 (14:10 +0200)
Instead of using isc_async_run() when closing StreamDNS handle, add
isc_job_t member to the isc_nmhandle_t structure and use isc_job_run()
to avoid allocation/deallocation on the StreamDNS hot-path.

lib/isc/netmgr/netmgr-int.h
lib/isc/netmgr/netmgr.c
lib/isc/netmgr/tlsstream.c

index eaf14f6637675570e38506d687b5aca4095943c1..c9d060a67fed0d51299a92a399a900587fd8ef9f 100644 (file)
@@ -245,6 +245,8 @@ struct isc_nmhandle {
        LINK(isc_nmhandle_t) active_link;
        LINK(isc_nmhandle_t) inactive_link;
        void *opaque;
+
+       isc_job_t job;
 };
 
 typedef union {
index 4fcc26e5ff35a675f42a6760568bb41fa88520e3..e7f61fee39dfd53691df3d39e200347f1153c440 100644 (file)
@@ -817,6 +817,7 @@ alloc_handle(isc_nmsocket_t *sock) {
                .magic = NMHANDLE_MAGIC,
                .active_link = ISC_LINK_INITIALIZER,
                .inactive_link = ISC_LINK_INITIALIZER,
+               .job = ISC_JOB_INITIALIZER,
        };
        isc_refcount_init(&handle->references, 1);
 
@@ -942,21 +943,38 @@ nmhandle_free(isc_nmsocket_t *sock, isc_nmhandle_t *handle) {
        isc_mem_put(sock->worker->mctx, handle, sizeof(*handle));
 }
 
+static void
+nmhandle__destroy(isc_nmhandle_t *handle) {
+       isc_nmsocket_t *sock = handle->sock;
+       handle->sock = NULL;
+
+#if defined(__SANITIZE_ADDRESS__) || defined(__SANITIZE_THREAD__)
+       nmhandle_free(sock, handle);
+#else
+       if (sock->active) {
+               ISC_LIST_APPEND(sock->inactive_handles, handle, inactive_link);
+       } else {
+               nmhandle_free(sock, handle);
+       }
+#endif
+
+       isc__nmsocket_detach(&sock);
+}
+
 static void
 isc__nm_closehandle_job(void *arg) {
-       isc_nmsocket_t *sock = arg;
+       isc_nmhandle_t *handle = arg;
+       isc_nmsocket_t *sock = handle->sock;
 
        sock->closehandle_cb(sock);
 
-       isc__nmsocket_detach(&sock);
+       nmhandle__destroy(handle);
 }
 
 static void
 nmhandle_destroy(isc_nmhandle_t *handle) {
        isc_nmsocket_t *sock = handle->sock;
 
-       handle->sock = NULL;
-
        if (handle->doreset != NULL) {
                handle->doreset(handle->opaque);
        }
@@ -974,27 +992,18 @@ nmhandle_destroy(isc_nmhandle_t *handle) {
 
        ISC_LIST_UNLINK(sock->active_handles, handle, active_link);
 
-#if defined(__SANITIZE_ADDRESS__) || defined(__SANITIZE_THREAD__)
-       nmhandle_free(sock, handle);
-#else
-       if (sock->active) {
-               ISC_LIST_APPEND(sock->inactive_handles, handle, inactive_link);
-       } else {
-               nmhandle_free(sock, handle);
+       if (sock->closehandle_cb == NULL) {
+               nmhandle__destroy(handle);
+               return;
        }
-#endif
 
        /*
-        * The handle is gone now. If the socket has a callback configured
-        * for that (e.g., to perform cleanup after request processing),
-        * call it now asynchronously.
+        * If the socket has a callback configured for that (e.g.,
+        * to perform cleanup after request processing), call it
+        * now asynchronously.
         */
-       if (sock->closehandle_cb != NULL) {
-               isc_async_run(sock->worker->loop, isc__nm_closehandle_job,
-                             sock);
-       } else {
-               isc___nmsocket_detach(&sock FLARG_PASS);
-       }
+       isc_job_run(sock->worker->loop, &handle->job, isc__nm_closehandle_job,
+                   handle);
 }
 
 void
index c1dfb0eb9555114f1539931c97938417b658038d..65de581fde4848b14255e5da6b6f254f58c984a9 100644 (file)
@@ -235,7 +235,8 @@ tls_failed_read_cb(isc_nmsocket_t *sock, const isc_result_t result) {
                tls_call_connect_cb(sock, handle, result);
                isc__nmsocket_clearcb(sock);
                isc_nmhandle_detach(&handle);
-       } else if (sock->recv_cb != NULL && sock->statichandle != NULL &&
+       } else if (sock->reading && sock->recv_cb != NULL &&
+                  sock->statichandle != NULL &&
                   (sock->recv_read || result == ISC_R_TIMEDOUT))
        {
                sock->recv_read = false;