]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Make the netmgr send callback to be asynchronous only when needed
authorOndřej Surý <ondrej@isc.org>
Thu, 24 Nov 2022 16:11:22 +0000 (17:11 +0100)
committerOndřej Surý <ondrej@isc.org>
Fri, 25 Nov 2022 14:46:25 +0000 (15:46 +0100)
Previously, the send callback would be synchronous only on success.  Add
an option (similar to what other callbacks have) to decide whether we
need the asynchronous send callback on a higher level.

On a general level, we need the asynchronous callbacks to happen only
when we are invoking the callback from the public API.  If the path to
the callback went through the libuv callback or netmgr callback, we are
already on asynchronous path, and there's no need to make the call to
the callback asynchronous again.

For the send callback, this means we need the asynchronous path for
failure paths inside the isc_nm_send() (which calls isc__nm_udp_send(),
isc__nm_tcp_send(), etc...) - all other invocations of the send callback
could be synchronous, because those are called from the respective libuv
send callbacks.

lib/isc/netmgr/netmgr-int.h
lib/isc/netmgr/netmgr.c
lib/isc/netmgr/tcp.c
lib/isc/netmgr/tcpdns.c
lib/isc/netmgr/tlsdns.c
lib/isc/netmgr/udp.c

index d17c18d81bae432e87f82af881481dbde9595042..4271990bffdc068fff276eb75a51b9f4f71890cf 100644 (file)
@@ -1946,7 +1946,7 @@ isc__nm_alloc_dnsbuf(isc_nmsocket_t *sock, size_t len);
 
 void
 isc__nm_failed_send_cb(isc_nmsocket_t *sock, isc__nm_uvreq_t *req,
-                      isc_result_t eresult);
+                      isc_result_t eresult, bool async);
 void
 isc__nm_failed_accept_cb(isc_nmsocket_t *sock, isc_result_t eresult);
 void
index 7583e531f5afe46741ff5129b6be5af8a2047ea6..f2b4127cf2ae34bb204543a042d046b5336674a0 100644 (file)
@@ -1324,12 +1324,12 @@ isc__nm_alloc_dnsbuf(isc_nmsocket_t *sock, size_t len) {
 
 void
 isc__nm_failed_send_cb(isc_nmsocket_t *sock, isc__nm_uvreq_t *req,
-                      isc_result_t eresult) {
+                      isc_result_t eresult, bool async) {
        REQUIRE(VALID_NMSOCK(sock));
        REQUIRE(VALID_UVREQ(req));
 
        if (req->cb.send != NULL) {
-               isc__nm_sendcb(sock, req, eresult, true);
+               isc__nm_sendcb(sock, req, eresult, async);
        } else {
                isc__nm_uvreq_put(&req, sock);
        }
index 9b2e9380035aa6fca14f49138f511ea1751573c1..239a24fb5a7f384b771ceaf31f0c363f38c97a33 100644 (file)
@@ -1029,7 +1029,7 @@ isc__nm_tcp_send(isc_nmhandle_t *handle, const isc_region_t *region,
        result = tcp_send_direct(sock, uvreq);
        if (result != ISC_R_SUCCESS) {
                isc__nm_incstats(sock, STATID_SENDFAIL);
-               isc__nm_failed_send_cb(sock, uvreq, result);
+               isc__nm_failed_send_cb(sock, uvreq, result, true);
        }
 
        return;
@@ -1050,7 +1050,8 @@ tcp_send_cb(uv_write_t *req, int status) {
 
        if (status < 0) {
                isc__nm_incstats(sock, STATID_SENDFAIL);
-               isc__nm_failed_send_cb(sock, uvreq, isc_uverr2result(status));
+               isc__nm_failed_send_cb(sock, uvreq, isc_uverr2result(status),
+                                      false);
                return;
        }
 
index e1016bea497f443293c96dd5f62d3dafa31b7a3b..e5f3178ace12fb294c55e76e280a709bd61848f8 100644 (file)
@@ -1147,7 +1147,8 @@ tcpdns_send_cb(uv_write_t *req, int status) {
 
        if (status < 0) {
                isc__nm_incstats(sock, STATID_SENDFAIL);
-               isc__nm_failed_send_cb(sock, uvreq, isc_uverr2result(status));
+               isc__nm_failed_send_cb(sock, uvreq, isc_uverr2result(status),
+                                      false);
                return;
        }
 
@@ -1233,7 +1234,7 @@ isc__nm_async_tcpdnssend(isc__networker_t *worker, isc__netievent_t *ev0) {
        return;
 fail:
        isc__nm_incstats(sock, STATID_SENDFAIL);
-       isc__nm_failed_send_cb(sock, uvreq, result);
+       isc__nm_failed_send_cb(sock, uvreq, result, true);
 }
 
 static void
index 528e6d442bbdce7806f59a142bb5adcce34cbe73..536aa2a7f4b9aecaa3aaeca125cde32c33f4a409 100644 (file)
@@ -1794,7 +1794,7 @@ isc__nm_async_tlsdnssend(isc__networker_t *worker, isc__netievent_t *ev0) {
        result = tlsdns_send_direct(sock, uvreq);
        if (result != ISC_R_SUCCESS) {
                isc__nm_incstats(sock, STATID_SENDFAIL);
-               isc__nm_failed_send_cb(sock, uvreq, result);
+               isc__nm_failed_send_cb(sock, uvreq, result, false);
        }
 }
 
index 0c5d4cf07d4363601dded851a01ece89a20b9aa4..6b7ae0810ce70d31ddebefad5f21fd5bb4340b14 100644 (file)
@@ -663,8 +663,10 @@ udp_send_cb(uv_udp_send_t *req, int status) {
        REQUIRE(sock->tid == isc_tid());
 
        if (status < 0) {
-               result = isc_uverr2result(status);
                isc__nm_incstats(sock, STATID_SENDFAIL);
+               isc__nm_failed_send_cb(sock, uvreq, isc_uverr2result(status),
+                                      false);
+               return;
        }
 
        isc__nm_sendcb(sock, uvreq, result, false);
@@ -744,7 +746,7 @@ isc__nm_udp_send(isc_nmhandle_t *handle, const isc_region_t *region,
        }
        return;
 fail:
-       isc__nm_failed_send_cb(sock, uvreq, result);
+       isc__nm_failed_send_cb(sock, uvreq, result, true);
 }
 
 static isc_result_t