]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
TLS: detect ISC_R_SHUTTINGDOWN and ISC_R_CANCELED cases properly
authorArtem Boldariev <artem@boldariev.com>
Thu, 25 May 2023 15:47:07 +0000 (18:47 +0300)
committerArtem Boldariev <artem@boldariev.com>
Wed, 6 Dec 2023 13:15:25 +0000 (15:15 +0200)
In the previous versions of the NM, detecting the case when worker is
shutting down was not that important and actual status code did not
matter much. However, that might be not the case all the time.

This commit makes necessary modifications to the code.

lib/isc/netmgr/tlsstream.c

index 18d2faadabb036a610933cc640c91024c4138ce0..6f4d4f495c385f728e9b55f020211dde8351074d 100644 (file)
@@ -355,11 +355,14 @@ tls_send_outgoing(isc_nmsocket_t *sock, bool finish, isc_nmhandle_t *tlshandle,
        size_t len = 0;
        bool new_send_req = false;
        isc_region_t used_region = { 0 };
+       bool shutting_down = isc__nm_closing(sock->worker);
 
-       if (inactive(sock)) {
+       if (shutting_down || inactive(sock)) {
                if (cb != NULL) {
+                       isc_result_t result = shutting_down ? ISC_R_SHUTTINGDOWN
+                                                           : ISC_R_CANCELED;
                        INSIST(VALID_NMHANDLE(tlshandle));
-                       cb(tlshandle, ISC_R_CANCELED, cbarg);
+                       cb(tlshandle, result, cbarg);
                }
                return (0);
        }
@@ -1024,7 +1027,10 @@ tls_send_direct(void *arg) {
        REQUIRE(VALID_NMSOCK(sock));
        REQUIRE(sock->tid == isc_tid());
 
-       if (inactive(sock)) {
+       if (isc__nm_closing(sock->worker)) {
+               req->cb.send(req->handle, ISC_R_SHUTTINGDOWN, req->cbarg);
+               goto done;
+       } else if (inactive(sock)) {
                req->cb.send(req->handle, ISC_R_CANCELED, req->cbarg);
                goto done;
        }
@@ -1084,7 +1090,10 @@ isc__nm_tls_read(isc_nmhandle_t *handle, isc_nm_recv_cb_t cb, void *cbarg) {
        REQUIRE(sock->statichandle == handle);
        REQUIRE(sock->tid == isc_tid());
 
-       if (inactive(sock)) {
+       if (isc__nm_closing(sock->worker)) {
+               cb(handle, ISC_R_SHUTTINGDOWN, NULL, cbarg);
+               return;
+       } else if (inactive(sock)) {
                cb(handle, ISC_R_CANCELED, NULL, cbarg);
                return;
        }
@@ -1238,6 +1247,9 @@ tcp_connected(isc_nmhandle_t *handle, isc_result_t result, void *cbarg) {
        if (isc__nm_closing(worker)) {
                result = ISC_R_SHUTTINGDOWN;
                goto error;
+       } else if (isc__nmsocket_closing(handle->sock)) {
+               result = ISC_R_CANCELED;
+               goto error;
        }
 
        /*