]> 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>
Wed, 25 Jun 2025 17:17:42 +0000 (18:17 +0100)
Fixes #37458.

(cherry picked from commit 5814acca9aa4354d121de4bf174851f092a6b643)
(cherry picked from commit e40fbaa18e747ee213303cd0ff780d95f5c812e9)

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

index bc53997a4960a18ff3992da6ecffbee7a91af0c1..5ce716cf2dd0f4aa0bd95c863a07929136c74b52 100644 (file)
@@ -199,6 +199,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)
@@ -208,6 +210,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++;
         }
 
@@ -271,6 +280,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 fd79b23341812b32c5ecb02e0adadbd57b7ad23f..8f93c419d647dde1ee71da9f361bb8e677b4acf3 100644 (file)
@@ -18,6 +18,7 @@ typedef struct DnsStubListenerExtra DnsStubListenerExtra;
 struct DnsQueryCandidate {
         unsigned n_ref;
         int error_code;
+        uint64_t generation;
 
         DnsQuery *query;
         DnsScope *scope;