From: Yu Watanabe Date: Wed, 14 May 2025 22:18:38 +0000 (+0900) Subject: resolve: exit from loop for transactions when transactions has been regenerated X-Git-Tag: v258-rc1~342 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5814acca9aa4354d121de4bf174851f092a6b643;p=thirdparty%2Fsystemd.git resolve: exit from loop for transactions when transactions has been regenerated Fixes #37458. --- diff --git a/src/resolve/resolved-dns-query.c b/src/resolve/resolved-dns-query.c index ea8236cec0c..3fd87d4b902 100644 --- a/src/resolve/resolved-dns-query.c +++ b/src/resolve/resolved-dns-query.c @@ -210,6 +210,8 @@ static int dns_query_candidate_go(DnsQueryCandidate *c) { /* Let's keep a reference to the query while we're operating */ keep_c = dns_query_candidate_ref(c); + uint64_t generation = c->generation; + /* Start the transactions that are not started yet */ SET_FOREACH(t, c->transactions) { if (t->state != DNS_TRANSACTION_NULL) @@ -219,6 +221,13 @@ static int dns_query_candidate_go(DnsQueryCandidate *c) { if (r < 0) return r; + if (c->generation != generation) + /* The transaction has been completed, and dns_transaction_complete() -> + * dns_query_candidate_notify() has been already called. Moreover, the query + * candidate has been regenerated, and the query should be already restarted. + * Let's exit from the loop now. */ + return 0; + n++; } @@ -280,6 +289,8 @@ static int dns_query_candidate_setup_transactions(DnsQueryCandidate *c) { dns_query_candidate_stop(c); + c->generation++; + if (c->query->question_bypass) { /* If this is a bypass query, then pass the original query packet along to the transaction */ diff --git a/src/resolve/resolved-dns-query.h b/src/resolve/resolved-dns-query.h index 9eec6d87d16..2aea9ad6600 100644 --- a/src/resolve/resolved-dns-query.h +++ b/src/resolve/resolved-dns-query.h @@ -10,6 +10,7 @@ typedef struct DnsQueryCandidate { unsigned n_ref; int error_code; + uint64_t generation; DnsQuery *query; DnsScope *scope;