]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
netmgr: close uv_loop properly
authorWitold Kręcicki <wpk@culm.net>
Fri, 15 Nov 2019 11:15:03 +0000 (12:15 +0100)
committerEvan Hunt <each@isc.org>
Mon, 18 Nov 2019 02:59:40 +0000 (18:59 -0800)
close the uv_handle for the worker async channel, and call
uv_loop_close() on shutdown to ensure that the event loop's
internal resources are properly freed.

lib/isc/netmgr/netmgr.c

index da8e73d81e42bc76e2ecb6eadff25ae202eb8cbc..3d65bca45726e8aaf251b779ad129c07e6d1da56 100644 (file)
@@ -174,6 +174,8 @@ nm_destroy(isc_nm_t **mgr0) {
                        isc_mem_put(mgr->mctx, ievent,
                                    sizeof(isc__netievent_storage_t));
                }
+               int r = uv_loop_close(&mgr->workers[i].loop);
+               INSIST(r == 0);
                isc_queue_destroy(mgr->workers[i].ievents);
                isc_mempool_destroy(&mgr->workers[i].mpool_bufs);
        }
@@ -350,6 +352,16 @@ nm_thread(void *worker0) {
 
                if (worker->finished) {
                        /* TODO walk the handles and free them! */
+                       /*
+                        * We need to launch the loop one more time
+                        * to make sure that worker->async is closed,
+                        * so that we can close the loop cleanly.
+                        * We don't care about the callback as in this
+                        * case we can be certain that uv_run will
+                        * eat this event.
+                        */
+                       uv_close((uv_handle_t *)&worker->async, NULL);
+                       uv_run(&worker->loop, UV_RUN_NOWAIT);
                        break;
                }