Skip to content

Commit e316f1e

Browse files
yuwatabluca
authored andcommitted
resolve: exit from loop for transactions when transactions has been regenerated
Fixes #37458. (cherry picked from commit 5814acca9aa4354d121de4bf174851f092a6b643) (cherry picked from commit e40fbaa18e747ee213303cd0ff780d95f5c812e9) (cherry picked from commit 579b59ac1db32ed5848474c59300419f28126117) (cherry picked from commit ce1d728)
1 parent 17cccd3 commit e316f1e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/resolve/resolved-dns-query.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ static int dns_query_candidate_go(DnsQueryCandidate *c) {
199199
/* Let's keep a reference to the query while we're operating */
200200
keep_c = dns_query_candidate_ref(c);
201201

202+
uint64_t generation = c->generation;
203+
202204
/* Start the transactions that are not started yet */
203205
SET_FOREACH(t, c->transactions) {
204206
if (t->state != DNS_TRANSACTION_NULL)
@@ -208,6 +210,13 @@ static int dns_query_candidate_go(DnsQueryCandidate *c) {
208210
if (r < 0)
209211
return r;
210212

213+
if (c->generation != generation)
214+
/* The transaction has been completed, and dns_transaction_complete() ->
215+
* dns_query_candidate_notify() has been already called. Moreover, the query
216+
* candidate has been regenerated, and the query should be already restarted.
217+
* Let's exit from the loop now. */
218+
return 0;
219+
211220
n++;
212221
}
213222

@@ -271,6 +280,8 @@ static int dns_query_candidate_setup_transactions(DnsQueryCandidate *c) {
271280

272281
dns_query_candidate_stop(c);
273282

283+
c->generation++;
284+
274285
if (c->query->question_bypass) {
275286
/* If this is a bypass query, then pass the original query packet along to the transaction */
276287

src/resolve/resolved-dns-query.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ typedef struct DnsStubListenerExtra DnsStubListenerExtra;
1818
struct DnsQueryCandidate {
1919
unsigned n_ref;
2020
int error_code;
21+
uint64_t generation;
2122

2223
DnsQuery *query;
2324
DnsScope *scope;

0 commit comments

Comments
 (0)