From 2f2d60a9898faeeb8e9c8d7b80061d7e7845687c Mon Sep 17 00:00:00 2001 From: Evan Hunt Date: Wed, 15 Jul 2020 17:57:58 -0700 Subject: [PATCH] limit the time we wait for netmgr to be destroyed if more than 10 seconds pass while we wait for netmgr events to finish running on shutdown, something is almost certainly wrong and we should assert and crash. --- lib/isc/netmgr/netmgr.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c index 4c6fdde1b2..ea5a54d0cd 100644 --- a/lib/isc/netmgr/netmgr.c +++ b/lib/isc/netmgr/netmgr.c @@ -393,6 +393,7 @@ isc_nm_closedown(isc_nm_t *mgr) { void isc_nm_destroy(isc_nm_t **mgr0) { isc_nm_t *mgr = NULL; + int counter = 0; REQUIRE(mgr0 != NULL); REQUIRE(VALID_NM(*mgr0)); @@ -407,7 +408,7 @@ isc_nm_destroy(isc_nm_t **mgr0) { /* * Wait for the manager to be dereferenced elsewhere. */ - while (isc_refcount_current(&mgr->references) > 1) { + while (isc_refcount_current(&mgr->references) > 1 && counter++ < 1000) { /* * Sometimes libuv gets stuck, pausing and unpausing * netmgr goes over all events in async queue for all @@ -423,6 +424,8 @@ isc_nm_destroy(isc_nm_t **mgr0) { #endif /* ifdef WIN32 */ } + INSIST(counter <= 1000); + /* * Detach final reference. */