]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
TLS: bail out earlier when NM is stopping
authorArtem Boldariev <artem@boldariev.com>
Mon, 27 Jun 2022 11:27:49 +0000 (14:27 +0300)
committerArtem Boldariev <artem@boldariev.com>
Tue, 12 Jul 2022 11:40:22 +0000 (14:40 +0300)
In some operations - most prominently when establishing connection -
it might be beneficial to bail out earlier when the network manager
is stopping.

The issue is backported from loopmgr branch, where such a change is
not only beneficial, but required.

lib/isc/netmgr/tlsstream.c

index adde8e069a22eb6bbd8d6785b1a7b775787161df..7ba09d8f4502a25f194bd2bcf5332538baf05427 100644 (file)
@@ -671,6 +671,9 @@ isc_nm_listentls(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface,
        isc_nmsocket_t *tsock = NULL;
 
        REQUIRE(VALID_NM(mgr));
+       if (atomic_load(&mgr->closing)) {
+               return (ISC_R_SHUTTINGDOWN);
+       }
 
        tlssock = isc_mem_get(mgr->mctx, sizeof(*tlssock));
 
@@ -829,6 +832,10 @@ isc__nm_tls_resumeread(isc_nmhandle_t *handle) {
        if (!atomic_compare_exchange_strong(&handle->sock->readpaused,
                                            &(bool){ false }, false))
        {
+               if (inactive(handle->sock)) {
+                       return;
+               }
+
                async_tls_do_bio(handle->sock);
        }
 }
@@ -926,6 +933,11 @@ isc_nm_tlsconnect(isc_nm_t *mgr, isc_sockaddr_t *local, isc_sockaddr_t *peer,
 
        REQUIRE(VALID_NM(mgr));
 
+       if (atomic_load(&mgr->closing)) {
+               cb(NULL, ISC_R_SHUTTINGDOWN, cbarg);
+               return;
+       }
+
        nsock = isc_mem_get(mgr->mctx, sizeof(*nsock));
        isc__nmsocket_init(nsock, mgr, isc_nm_tlssocket, local);
        nsock->result = ISC_R_UNSET;