]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix isc_nm_httpconnect to check for shuttindown condition
authorOndřej Surý <ondrej@isc.org>
Tue, 28 Mar 2023 07:40:59 +0000 (09:40 +0200)
committerOndřej Surý <ondrej@isc.org>
Wed, 29 Mar 2023 06:27:05 +0000 (08:27 +0200)
The isc_nm_httpconnect() would succeed even if the netmgr would be
already shuttingdown.  This has been fixed and the unit test has been
updated to cope with fact that the handle would be NULL when
isc_nm_httpconnect() returns with an error.

(cherry picked from commit 665f8bb78d1439f18ff6e5e3ebef8728a4985f45)

tests/isc/doh_test.c

index 9f19b4e31b6ddea2230be86dbca6fd75f8973059..ab74813cff4b582a0d1277ee853bc6212f016239 100644 (file)
@@ -130,8 +130,6 @@ static void
 connect_send_cb(isc_nmhandle_t *handle, isc_result_t result, void *arg) {
        csdata_t data;
 
-       REQUIRE(VALID_NMHANDLE(handle));
-
        (void)atomic_fetch_sub(&active_cconnects, 1);
        memmove(&data, arg, sizeof(data));
        isc_mem_put(handle->sock->mgr->mctx, arg, sizeof(data));
@@ -139,6 +137,8 @@ connect_send_cb(isc_nmhandle_t *handle, isc_result_t result, void *arg) {
                goto error;
        }
 
+       REQUIRE(VALID_NMHANDLE(handle));
+
        result = isc__nm_http_request(handle, &data.region, data.reply_cb,
                                      data.cb_arg);
        if (result != ISC_R_SUCCESS) {
@@ -688,34 +688,33 @@ ISC_RUN_TEST_IMPL(doh_timeout_recovery_GET) {
 static void
 doh_receive_send_reply_cb(isc_nmhandle_t *handle, isc_result_t eresult,
                          isc_region_t *region, void *cbarg) {
-       isc_nmhandle_t *thandle = NULL;
-       assert_non_null(handle);
        UNUSED(region);
 
-       isc_nmhandle_attach(handle, &thandle);
-       if (eresult == ISC_R_SUCCESS) {
-               int_fast64_t sends = atomic_fetch_sub(&nsends, 1);
-               atomic_fetch_add(&csends, 1);
-               atomic_fetch_add(&creads, 1);
-               if (sends > 0 && cbarg == NULL) {
-                       size_t i;
-                       for (i = 0; i < NWRITES / 2; i++) {
-                               eresult = isc__nm_http_request(
-                                       handle,
-                                       &(isc_region_t){
-                                               .base = (uint8_t *)send_msg.base,
-                                               .length = send_msg.len },
-                                       doh_receive_send_reply_cb, (void *)1);
-                               if (eresult == ISC_R_CANCELED) {
-                                       break;
-                               }
-                               assert_true(eresult == ISC_R_SUCCESS);
+       if (eresult != ISC_R_SUCCESS) {
+               atomic_store(&was_error, true);
+               return;
+       }
+
+       assert_non_null(handle);
+
+       int_fast64_t sends = atomic_fetch_sub(&nsends, 1);
+       atomic_fetch_add(&csends, 1);
+       atomic_fetch_add(&creads, 1);
+       if (sends > 0 && cbarg == NULL) {
+               size_t i;
+               for (i = 0; i < NWRITES / 2; i++) {
+                       eresult = isc__nm_http_request(
+                               handle,
+                               &(isc_region_t){
+                                       .base = (uint8_t *)send_msg.base,
+                                       .length = send_msg.len },
+                               doh_receive_send_reply_cb, (void *)1);
+                       if (eresult == ISC_R_CANCELED) {
+                               break;
                        }
+                       assert_true(eresult == ISC_R_SUCCESS);
                }
-       } else {
-               atomic_store(&was_error, true);
        }
-       isc_nmhandle_detach(&thandle);
 }
 
 static isc_threadresult_t