Skip to content
This repository was archived by the owner on Aug 13, 2025. It is now read-only.

Commit 665f8bb

Browse files
committed
Fix isc_nm_httpconnect to check for shuttindown condition
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.
1 parent 9317aa9 commit 665f8bb

File tree

2 files changed

+31
-27
lines changed

2 files changed

+31
-27
lines changed

lib/isc/netmgr/http.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,11 @@ isc_nm_httpconnect(isc_nm_t *mgr, isc_sockaddr_t *local, isc_sockaddr_t *peer,
14641464
REQUIRE(uri != NULL);
14651465
REQUIRE(*uri != '\0');
14661466

1467+
if (isc__nm_closing(worker)) {
1468+
cb(NULL, ISC_R_SHUTTINGDOWN, cbarg);
1469+
return;
1470+
}
1471+
14671472
if (local == NULL) {
14681473
isc_sockaddr_anyofpf(&local_interface, peer->type.sa.sa_family);
14691474
local = &local_interface;

tests/isc/doh_test.c

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,15 @@ static void
134134
connect_send_cb(isc_nmhandle_t *handle, isc_result_t result, void *arg) {
135135
csdata_t data;
136136

137-
REQUIRE(VALID_NMHANDLE(handle));
138-
139137
(void)atomic_fetch_sub(&active_cconnects, 1);
140138
memmove(&data, arg, sizeof(data));
141139
isc_mem_put(data.mctx, arg, sizeof(data));
142140
if (result != ISC_R_SUCCESS) {
143141
goto error;
144142
}
145143

144+
REQUIRE(VALID_NMHANDLE(handle));
145+
146146
result = isc__nm_http_request(handle, &data.region, data.reply_cb,
147147
data.cb_arg);
148148
if (result != ISC_R_SUCCESS) {
@@ -675,39 +675,38 @@ doh_connect_thread(void *arg);
675675
static void
676676
doh_receive_send_reply_cb(isc_nmhandle_t *handle, isc_result_t eresult,
677677
isc_region_t *region, void *cbarg) {
678-
isc_nmhandle_t *thandle = NULL;
679678
isc_nm_t *connect_nm = (isc_nm_t *)cbarg;
680679

680+
if (eresult != ISC_R_SUCCESS) {
681+
return;
682+
}
683+
681684
assert_non_null(handle);
682685
UNUSED(region);
683686

684-
isc_nmhandle_attach(handle, &thandle);
685-
if (eresult == ISC_R_SUCCESS) {
686-
int_fast64_t sends = atomic_fetch_sub(&nsends, 1);
687-
atomic_fetch_add(&csends, 1);
688-
atomic_fetch_add(&creads, 1);
689-
if (sends > 0 && connect_nm != NULL) {
690-
size_t i;
691-
for (i = 0; i < NWRITES / 2; i++) {
692-
eresult = isc__nm_http_request(
693-
handle,
694-
&(isc_region_t){
695-
.base = (uint8_t *)send_msg.base,
696-
.length = send_msg.len },
697-
doh_receive_send_reply_cb, NULL);
698-
if (eresult == ISC_R_CANCELED) {
699-
break;
700-
}
701-
assert_true(eresult == ISC_R_SUCCESS);
687+
int_fast64_t sends = atomic_fetch_sub(&nsends, 1);
688+
atomic_fetch_add(&csends, 1);
689+
atomic_fetch_add(&creads, 1);
690+
if (sends > 0 && connect_nm != NULL) {
691+
size_t i;
692+
for (i = 0; i < NWRITES / 2; i++) {
693+
eresult = isc__nm_http_request(
694+
handle,
695+
&(isc_region_t){
696+
.base = (uint8_t *)send_msg.base,
697+
.length = send_msg.len },
698+
doh_receive_send_reply_cb, NULL);
699+
if (eresult == ISC_R_CANCELED) {
700+
break;
702701
}
703-
704-
isc_job_run(loopmgr, doh_connect_thread, connect_nm);
705-
}
706-
if (sends <= 0) {
707-
isc_loopmgr_shutdown(loopmgr);
702+
assert_true(eresult == ISC_R_SUCCESS);
708703
}
704+
705+
isc_job_run(loopmgr, doh_connect_thread, connect_nm);
706+
}
707+
if (sends <= 0) {
708+
isc_loopmgr_shutdown(loopmgr);
709709
}
710-
isc_nmhandle_detach(&thandle);
711710
}
712711

713712
static void

0 commit comments

Comments
 (0)