]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolve: exit from loop for transactions when transactions has been regenerated
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 14 May 2025 22:18:38 +0000 (07:18 +0900)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 10 Jun 2025 16:30:03 +0000 (17:30 +0100)
Fixes #37458.

src/resolve/resolved-dns-query.c
src/resolve/resolved-dns-query.h

index ea8236cec0cf28cc91d5b28cbb7afa3ad80e58e2..3fd87d4b90221f2d488607c0ff10fede1f801791 100644 (file)
@@ -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 */
 
index 9eec6d87d16d71c8ee964c7ea19c77526950c635..2aea9ad660077b63f64a834b219cadcad965e696 100644 (file)
@@ -10,6 +10,7 @@
 typedef struct DnsQueryCandidate {
         unsigned n_ref;
         int error_code;
+        uint64_t generation;
 
         DnsQuery *query;
         DnsScope *scope;