]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Don't clear dig lookup if it was already cleared
authorOndřej Surý <ondrej@sury.org>
Tue, 4 May 2021 12:25:55 +0000 (14:25 +0200)
committerEvan Hunt <each@isc.org>
Fri, 7 May 2021 21:28:30 +0000 (14:28 -0700)
This workarounds couple of races where the current_lookup would be
already detached during shutting down the dig, but still processing the
pending reads.

bin/dig/dighost.c

index a941bcf87d6048d71c9b235dc6ee646266daa73d..7ae651e517c288f3882fe976df01c34a423c01ba 100644 (file)
@@ -1754,13 +1754,18 @@ start_lookup(void) {
  * decremented, current_lookup will not be set to NULL.)
  */
 static void
-clear_current_lookup() {
+clear_current_lookup(void) {
        dig_lookup_t *lookup = current_lookup;
 
        INSIST(!free_now);
 
        debug("clear_current_lookup()");
 
+       if (lookup == NULL) {
+               debug("current_lookup is already detached");
+               return;
+       }
+
        if (ISC_LIST_HEAD(lookup->q) != NULL) {
                debug("still have a worker");
                return;
@@ -2907,6 +2912,7 @@ udp_ready(isc_nmhandle_t *handle, isc_result_t eresult, void *arg) {
                              isc_result_totext(eresult));
                }
 
+               cancel_lookup(l);
                lookup_detach(&l);
                query_detach(&query);
                return;
@@ -3574,16 +3580,19 @@ recv_done(isc_nmhandle_t *handle, isc_result_t eresult, isc_region_t *region,
              region, arg);
 
        LOCK_LOOKUP;
-       lookup_attach(query->lookup, &l);
 
        isc_refcount_decrement0(&recvcount);
        debug("recvcount=%" PRIuFAST32, isc_refcount_current(&recvcount));
 
        if (eresult == ISC_R_CANCELED) {
                debug("recv_done: cancel");
-               goto detach_query;
+               isc_nmhandle_detach(&query->readhandle);
+               query_detach(&query);
+               return;
        }
 
+       lookup_attach(query->lookup, &l);
+
        if (query->lookup->use_usec) {
                TIME_NOW_HIRES(&query->time_recv);
        } else {
@@ -4204,7 +4213,13 @@ cancel_all(void) {
                        }
                        query_detach(&q);
                }
-               lookup_detach(&current_lookup);
+
+               /*
+                * current_lookup could have been detached via query_detach().
+                */
+               if (current_lookup != NULL) {
+                       lookup_detach(&current_lookup);
+               }
        }
        l = ISC_LIST_HEAD(lookup_list);
        while (l != NULL) {