]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
always return true in ns_interfacemgr_listeningon if interfacemgr is shutting down
authorWitold Kręcicki <wpk@isc.org>
Sat, 7 Dec 2019 22:44:16 +0000 (23:44 +0100)
committerWitold Kręcicki <wpk@isc.org>
Mon, 9 Dec 2019 20:44:04 +0000 (21:44 +0100)
to avoid deadlocks on shutdown.

lib/ns/interfacemgr.c

index 2dd03a0eee943d7e1c07368d118c0f83e8798802..3bbeee2a50be3bf36755659e674c4b7e905f4b5c 100644 (file)
@@ -83,6 +83,7 @@ struct ns_interfacemgr {
        ISC_LIST(isc_sockaddr_t) listenon;
        int                     backlog;        /*%< Listen queue size */
        unsigned int            udpdisp;        /*%< UDP dispatch count */
+       atomic_bool             shuttingdown;   /*%< Interfacemgr is shutting down */
 #ifdef USE_ROUTE_SOCKET
        isc_task_t *            task;
        isc_socket_t *          route;
@@ -217,6 +218,7 @@ ns_interfacemgr_create(isc_mem_t *mctx,
        mgr->listenon4 = NULL;
        mgr->listenon6 = NULL;
        mgr->udpdisp = udpdisp;
+       atomic_init(&mgr->shuttingdown, false);
 
        ISC_LIST_INIT(mgr->interfaces);
        ISC_LIST_INIT(mgr->listenon);
@@ -360,6 +362,7 @@ ns_interfacemgr_shutdown(ns_interfacemgr_t *mgr) {
         * consider all interfaces "old".
         */
        mgr->generation++;
+       atomic_store(&mgr->shuttingdown, true);
 #ifdef USE_ROUTE_SOCKET
        LOCK(&mgr->lock);
        if (mgr->route != NULL) {
@@ -1230,7 +1233,13 @@ ns_interfacemgr_listeningon(ns_interfacemgr_t *mgr,
        bool result = false;
 
        REQUIRE(NS_INTERFACEMGR_VALID(mgr));
-
+       /*
+        * If the manager is shutting down it's safer to
+        * return true.
+        */
+       if (atomic_load(&mgr->shuttingdown)) {
+               return (true);
+       }
        LOCK(&mgr->lock);
        for (old = ISC_LIST_HEAD(mgr->listenon);
             old != NULL;