From a0b123a06e6cdbf931a973c91129776a90a6ce8b Mon Sep 17 00:00:00 2001
From: Mark Andrews <marka@isc.org>
Date: Mon, 7 Sep 2020 13:21:10 +1000
Subject: [PATCH] Address lock order reversals when shutting down a view.

Release view->lock before calling dns_resolver_shutdown,
dns_adb_shutdown, and dns_requestmgr_shutdown.
Conflict: NA
Reference: https://gitlab.isc.org/isc-projects/bind9/-/commit/a0b123a06e6cdbf931a973c91129776a90a6ce8b
---
 lib/dns/view.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/lib/dns/view.c b/lib/dns/view.c
index 1726b43f9e..a7ba613990 100644
--- a/lib/dns/view.c
+++ b/lib/dns/view.c
@@ -599,12 +599,21 @@ view_flushanddetach(dns_view_t **viewp, bool flush) {
 		dns_zone_t *mkzone = NULL, *rdzone = NULL;
 
 		LOCK(&view->lock);
-		if (!RESSHUTDOWN(view))
+		if (!RESSHUTDOWN(view)) {
+			UNLOCK(&view->lock);
 			dns_resolver_shutdown(view->resolver);
-		if (!ADBSHUTDOWN(view))
+			LOCK(&view->lock);
+		}
+		if (!ADBSHUTDOWN(view)) {
+			UNLOCK(&view->lock);
 			dns_adb_shutdown(view->adb);
-		if (!REQSHUTDOWN(view))
+			LOCK(&view->lock);
+		}
+		if (!REQSHUTDOWN(view)) {
+			UNLOCK(&view->lock);
 			dns_requestmgr_shutdown(view->requestmgr);
+			LOCK(&view->lock);
+		}
 		if (view->acache != NULL)
 			dns_acache_shutdown(view->acache);
 		if (view->zonetable != NULL) {
-- 
2.23.0

