From 9244f96f52222bf67fe9d445dce6895adf16f20a Mon Sep 17 00:00:00 2001 From: Jeff Elsloo Date: Fri, 14 Jan 2022 09:31:16 -0700 Subject: [PATCH] Fixes a scoping bug that leads to "sticky" weights * Due to scoping, the last user-provided weight seen will be applied to all subsequent hosts that lack a weight * Added a constant to specify the default weight * Resets the weight to default prior to parsing each parent's configuration to ensure defaults are used when no weight exists --- proxy/ParentSelection.cc | 3 ++- proxy/ParentSelection.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/proxy/ParentSelection.cc b/proxy/ParentSelection.cc index f06d28f733d..8c0b54e0723 100644 --- a/proxy/ParentSelection.cc +++ b/proxy/ParentSelection.cc @@ -446,7 +446,7 @@ ParentRecord::ProcessParents(char *val, bool isPrimary) int port = 0; char *tmp = nullptr, *tmp2 = nullptr, *tmp3 = nullptr; const char *errPtr = nullptr; - float weight = 1.0; + float weight = DEFAULT_PARENT_WEIGHT; if (parents != nullptr && isPrimary == true) { return "Can not specify more than one set of parents"; @@ -470,6 +470,7 @@ ParentRecord::ProcessParents(char *val, bool isPrimary) // Loop through the set of parents specified // for (int i = 0; i < numTok; i++) { + weight = DEFAULT_PARENT_WEIGHT; // reset weight to the default current = pTok[i]; // Find the parent port diff --git a/proxy/ParentSelection.h b/proxy/ParentSelection.h index 8fcbedc9701..69d20241fa8 100644 --- a/proxy/ParentSelection.h +++ b/proxy/ParentSelection.h @@ -43,6 +43,7 @@ #include #define MAX_PARENTS 64 +#define DEFAULT_PARENT_WEIGHT 1.0 struct RequestData; struct matcher_line;