From 8a76d21f5194cb31e514860319b8fcae2d2648be Mon Sep 17 00:00:00 2001 From: keith2008 <56985076@qq.com> Date: Tue, 23 Aug 2016 08:42:30 +0800 Subject: [PATCH 1/5] TS-4743: parent use consistent_hash Strategy may cause crash while first parent is not set --- proxy/ParentConsistentHash.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/ParentConsistentHash.cc b/proxy/ParentConsistentHash.cc index 40b4440a213..9e10307b632 100644 --- a/proxy/ParentConsistentHash.cc +++ b/proxy/ParentConsistentHash.cc @@ -166,7 +166,7 @@ ParentConsistentHash::selectParent(const ParentSelectionPolicy *policy, bool fir } Debug("parent_select", "wrap_around[PRIMARY]: %d, wrap_around[SECONDARY]: %d", wrap_around[PRIMARY], wrap_around[SECONDARY]); if (!wrap_around[PRIMARY] || (chash[SECONDARY] != NULL)) { - Debug("parent_select", "Selected parent %s is not available, looking up another parent.", pRec->hostname); + Debug("parent_select", "Selected parent %s is not available, looking up another parent.", pRec ? pRec->hostname:"[NULL]"); if (chash[SECONDARY] != NULL && !wrap_around[SECONDARY]) { fhash = chash[SECONDARY]; last_lookup = SECONDARY; From 3deb52397b047455ba8aba3e5132e3daafa980ad Mon Sep 17 00:00:00 2001 From: keith2008 <56985076@qq.com> Date: Tue, 23 Aug 2016 08:51:44 +0800 Subject: [PATCH 2/5] TS-4744: ParentConsistentHash::selectParent may select the unavailable parent --- proxy/ParentConsistentHash.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/proxy/ParentConsistentHash.cc b/proxy/ParentConsistentHash.cc index 9e10307b632..8e5822005ae 100644 --- a/proxy/ParentConsistentHash.cc +++ b/proxy/ParentConsistentHash.cc @@ -143,6 +143,8 @@ ParentConsistentHash::selectParent(const ParentSelectionPolicy *policy, bool fir if (prtmp) { pRec = (parents[last_lookup] + prtmp->idx); } + else + pRec = NULL; } while (prtmp && strcmp(prtmp->hostname, result->hostname) == 0); } } @@ -166,7 +168,7 @@ ParentConsistentHash::selectParent(const ParentSelectionPolicy *policy, bool fir } Debug("parent_select", "wrap_around[PRIMARY]: %d, wrap_around[SECONDARY]: %d", wrap_around[PRIMARY], wrap_around[SECONDARY]); if (!wrap_around[PRIMARY] || (chash[SECONDARY] != NULL)) { - Debug("parent_select", "Selected parent %s is not available, looking up another parent.", pRec ? pRec->hostname:"[NULL]"); + Debug("parent_select", "Selected parent %s is not available, looking up another parent.", pRec->hostname); if (chash[SECONDARY] != NULL && !wrap_around[SECONDARY]) { fhash = chash[SECONDARY]; last_lookup = SECONDARY; @@ -185,6 +187,8 @@ ParentConsistentHash::selectParent(const ParentSelectionPolicy *policy, bool fir pRec = (parents[last_lookup] + prtmp->idx); Debug("parent_select", "Selected a new parent: %s.", pRec->hostname); } + else + pRec = NULL; } if (wrap_around[PRIMARY] && chash[SECONDARY] == NULL) { Debug("parent_select", "No available parents."); From 49beaa5b5fd712c1d8383b081fc8479ec680ae0a Mon Sep 17 00:00:00 2001 From: keith2008 <56985076@qq.com> Date: Tue, 23 Aug 2016 08:58:54 +0800 Subject: [PATCH 3/5] TS-4745: pRecord.failCount not init in ParentRecord::ProcessParents --- proxy/ParentConsistentHash.cc | 4 ---- proxy/ParentSelection.cc | 2 ++ 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/proxy/ParentConsistentHash.cc b/proxy/ParentConsistentHash.cc index 8e5822005ae..40b4440a213 100644 --- a/proxy/ParentConsistentHash.cc +++ b/proxy/ParentConsistentHash.cc @@ -143,8 +143,6 @@ ParentConsistentHash::selectParent(const ParentSelectionPolicy *policy, bool fir if (prtmp) { pRec = (parents[last_lookup] + prtmp->idx); } - else - pRec = NULL; } while (prtmp && strcmp(prtmp->hostname, result->hostname) == 0); } } @@ -187,8 +185,6 @@ ParentConsistentHash::selectParent(const ParentSelectionPolicy *policy, bool fir pRec = (parents[last_lookup] + prtmp->idx); Debug("parent_select", "Selected a new parent: %s.", pRec->hostname); } - else - pRec = NULL; } if (wrap_around[PRIMARY] && chash[SECONDARY] == NULL) { Debug("parent_select", "No available parents."); diff --git a/proxy/ParentSelection.cc b/proxy/ParentSelection.cc index c7d2eb0145c..a344d0d1ec4 100644 --- a/proxy/ParentSelection.cc +++ b/proxy/ParentSelection.cc @@ -434,6 +434,7 @@ ParentRecord::ProcessParents(char *val, bool isPrimary) this->parents[i].hostname[tmp - current] = '\0'; this->parents[i].port = port; this->parents[i].failedAt = 0; + this->parents[i].failCount = 0; this->parents[i].scheme = scheme; this->parents[i].idx = i; this->parents[i].name = this->parents[i].hostname; @@ -444,6 +445,7 @@ ParentRecord::ProcessParents(char *val, bool isPrimary) this->secondary_parents[i].hostname[tmp - current] = '\0'; this->secondary_parents[i].port = port; this->secondary_parents[i].failedAt = 0; + this->secondary_parents[i].failCount = 0; this->secondary_parents[i].scheme = scheme; this->secondary_parents[i].idx = i; this->secondary_parents[i].name = this->secondary_parents[i].hostname; From 1159f47044e7add14ccaa84bf110895e244599b0 Mon Sep 17 00:00:00 2001 From: keith2008 <56985076@qq.com> Date: Tue, 23 Aug 2016 09:12:22 +0800 Subject: [PATCH 4/5] TS-4746: ParentRecord *secondary_parents malloc, but no place free,which will cause memery leak --- proxy/ParentSelection.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/proxy/ParentSelection.cc b/proxy/ParentSelection.cc index a344d0d1ec4..3d316256955 100644 --- a/proxy/ParentSelection.cc +++ b/proxy/ParentSelection.cc @@ -434,7 +434,6 @@ ParentRecord::ProcessParents(char *val, bool isPrimary) this->parents[i].hostname[tmp - current] = '\0'; this->parents[i].port = port; this->parents[i].failedAt = 0; - this->parents[i].failCount = 0; this->parents[i].scheme = scheme; this->parents[i].idx = i; this->parents[i].name = this->parents[i].hostname; @@ -445,7 +444,6 @@ ParentRecord::ProcessParents(char *val, bool isPrimary) this->secondary_parents[i].hostname[tmp - current] = '\0'; this->secondary_parents[i].port = port; this->secondary_parents[i].failedAt = 0; - this->secondary_parents[i].failCount = 0; this->secondary_parents[i].scheme = scheme; this->secondary_parents[i].idx = i; this->secondary_parents[i].name = this->secondary_parents[i].hostname; @@ -714,7 +712,12 @@ ParentRecord::UpdateMatch(ParentResult *result, RequestData *rdata) ParentRecord::~ParentRecord() { - ats_free(parents); + if(parents != NULL) { + ats_free(parents); + } + if(secondary_parents != NULL) { + ats_free(secondary_parents); + } delete selection_strategy; delete unavailable_server_retry_responses; } From 46671f91f337cd28dbc084dedde903382e3b3c38 Mon Sep 17 00:00:00 2001 From: keith2008 <56985076@qq.com> Date: Tue, 23 Aug 2016 09:17:40 +0800 Subject: [PATCH 5/5] TS-4747: if the connection of parent is notalive, not make the parent host down,which will select the the unavailablehost again --- proxy/ParentSelection.cc | 7 +------ proxy/http/HttpTransact.cc | 1 + 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/proxy/ParentSelection.cc b/proxy/ParentSelection.cc index 3d316256955..c7d2eb0145c 100644 --- a/proxy/ParentSelection.cc +++ b/proxy/ParentSelection.cc @@ -712,12 +712,7 @@ ParentRecord::UpdateMatch(ParentResult *result, RequestData *rdata) ParentRecord::~ParentRecord() { - if(parents != NULL) { - ats_free(parents); - } - if(secondary_parents != NULL) { - ats_free(secondary_parents); - } + ats_free(parents); delete selection_strategy; delete unavailable_server_retry_responses; } diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc index ff4c1977657..66fcae3e809 100644 --- a/proxy/http/HttpTransact.cc +++ b/proxy/http/HttpTransact.cc @@ -3607,6 +3607,7 @@ HttpTransact::handle_response_from_parent(State *s) default: { LookingUp_t next_lookup = UNDEFINED_LOOKUP; DebugTxn("http_trans", "[hrfp] connection not alive"); + s->state_machine->do_hostdb_update_if_necessary(); SET_VIA_STRING(VIA_DETAIL_PP_CONNECT, VIA_DETAIL_PP_FAILURE); ink_assert(s->hdr_info.server_request.valid());