From cd4601f332d9e78991e605a3fc1d29a23ba0a2de Mon Sep 17 00:00:00 2001 From: John Rushford Date: Thu, 16 Jan 2020 20:01:23 +0000 Subject: [PATCH] Fixes Issue #6321 caused when proxy.config.http.no_dns_just_forward_to_parent is enabled. When this configuration variable is enabled, a parent selection strategies findParent() function is called twice on each transaction resulting in unexpected results such as every other parent is only used in a strict round robin strategy. (cherry picked from commit 98893b6df4e9acfe68c770ec6c8ef75bcebd0919) Conflicts: proxy/ParentSelection.cc --- proxy/ParentSelection.cc | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/proxy/ParentSelection.cc b/proxy/ParentSelection.cc index 296fa99e387..057a81ee221 100644 --- a/proxy/ParentSelection.cc +++ b/proxy/ParentSelection.cc @@ -140,6 +140,9 @@ ParentConfigParams::findParent(HttpRequestData *rdata, ParentResult *result, uns return; } + // Initialize the result structure + result->reset(); + tablePtr->Match(rdata, result); rec = result->rec; @@ -240,17 +243,38 @@ ParentConfigParams::nextParent(HttpRequestData *rdata, ParentResult *result, uns bool ParentConfigParams::parentExists(HttpRequestData *rdata) { - unsigned int fail_threshold = policy.FailThreshold; - unsigned int retry_time = policy.ParentRetryTime; + P_table *tablePtr = parent_table; + ParentRecord *rec = nullptr; ParentResult result; - findParent(rdata, &result, fail_threshold, retry_time); + // Initialize the result structure; + result.reset(); - if (result.result == PARENT_SPECIFIED) { - return true; - } else { + tablePtr->Match(rdata, &result); + rec = result.rec; + + if (rec == nullptr) { + Debug("parent_select", "No matching parent record was found for the request."); return false; } + + if (rec->num_parents > 0) { + for (int ii = 0; ii < rec->num_parents; ii++) { + if (rec->parents[ii].available) { + Debug("parent_select", "found available parent: %s", rec->parents[ii].hostname); + return true; + } + } + } + if (rec->secondary_parents && rec->num_secondary_parents > 0) { + for (int ii = 0; ii < rec->num_secondary_parents; ii++) { + if (rec->secondary_parents[ii].available) { + Debug("parent_select", "found available parent: %s", rec->secondary_parents[ii].hostname); + return true; + } + } + } + return false; } int ParentConfig::m_id = 0;