From 1f7ccaba1bbb245cf06918fd397a0a1743f263f1 Mon Sep 17 00:00:00 2001
From: Mark Andrews <marka@isc.org>
Date: Fri, 21 Aug 2020 18:35:38 +1000
Subject: [PATCH] Prevent loads_pending going to zero while kicking the loads.

Conflict: NA
Reference: https://gitlab.isc.org/isc-projects/bind9/-/commit/1f7ccaba1bbb245cf06918fd397a0a1743f263f1
---
 lib/dns/zt.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/dns/zt.c b/lib/dns/zt.c
index 04d7823d8b..8098b90d1f 100644
--- a/lib/dns/zt.c
+++ b/lib/dns/zt.c
@@ -296,9 +296,13 @@ dns_zt_asyncload2(dns_zt_t *zt, dns_zt_allloaded_t alldone, void *arg,
 	RWLOCK(&zt->rwlock, isc_rwlocktype_write);
 
 	INSIST(zt->loads_pending == 0);
+	/*
+	 * Prevent loads_pending going to zero while kicking off the loads.
+	 */
+	zt->loads_pending++;
 	result = dns_zt_apply2(zt, false, NULL, asyncload, &params);
 
-	pending = zt->loads_pending;
+	pending = --zt->loads_pending;
 	if (pending != 0) {
 		zt->loaddone = alldone;
 		zt->loaddone_arg = arg;
-- 
2.23.0

