]> 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 12:36:10 +0000 (13:36 +0100)
Fixes #37458.

(cherry picked from commit 5814acca9aa4354d121de4bf174851f092a6b643)

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

index 700c40a8aeb42e4f35a7e7feafde46570675c4a7..62a19aaac2b333d81e8317d2b8bd7140dd0affe2 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 1097e90dc093906bf81f62afb3cd62f258916fa3..3247fbd7cef24cb684bb979af914d8ab0b52c661 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;