dig: prevent query from being detached if udpconnect fails on first attempt

FreeBSD sometimes returns spurious errors in UDP connect() attempts,
so we try a few times before giving up. However, each failed attempt
triggers a call to udp_ready() in dighost.c, and that was causing
the query object to be detached prematurely.
This commit is contained in:
Evan Hunt 2020-11-05 14:15:14 -08:00 committed by Ondřej Surý
parent 6d63ffe46d
commit 88f5f3915b
2 changed files with 7 additions and 4 deletions

View file

@ -2897,7 +2897,9 @@ udp_ready(isc_nmhandle_t *handle, isc_result_t eresult, void *arg) {
debug("udp setup failed: %s",
isc_result_totext(eresult));
}
query_detach(&query);
if (query->tries == 0) {
query_detach(&query);
}
return;
}
@ -2933,7 +2935,6 @@ static void
start_udp(dig_query_t *query) {
isc_result_t result;
dig_query_t *next = NULL;
int i = 0;
REQUIRE(DIG_VALID_QUERY(query));
@ -2985,6 +2986,7 @@ start_udp(dig_query_t *query) {
}
}
query->tries = 3;
do {
int local_timeout = timeout * 1000;
if (local_timeout == 0) {
@ -2996,11 +2998,11 @@ start_udp(dig_query_t *query) {
* in a spurious transient EADDRINUSE. Try a few more times
* before giving up.
*/
debug("isc_nm_udpconnect(): try %d", i + 1);
debug("isc_nm_udpconnect(): %d tries left", --query->tries);
result = isc_nm_udpconnect(netmgr, (isc_nmiface_t *)&localaddr,
(isc_nmiface_t *)&query->sockaddr,
udp_ready, query, local_timeout, 0);
} while (result != ISC_R_SUCCESS && i++ < 2);
} while (result != ISC_R_SUCCESS && query->tries > 0);
check_result(result, "isc_nm_udpconnect");
}

View file

@ -199,6 +199,7 @@ struct dig_query {
isc_time_t time_recv;
uint64_t byte_count;
isc_timer_t *timer;
uint8_t tries;
};
struct dig_server {