This is an automated email from the ASF dual-hosted git repository. cmcfarlen pushed a commit to branch 10.2.x in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 2f8a34e66c4d393d108069bd118c6aa272c39cb7 Author: Chris McFarlen <[email protected]> AuthorDate: Mon May 4 17:14:19 2026 -0500 Fix index issue with records in HostDBRecord::select_best_srv (#13132) * Fix index issue with records in HostDBRecord::select_best_srv * review comments (cherry picked from commit 79f8b31b2ac3420d1456bbb6f4ff6c1bcd6e0e1c) --- src/iocore/hostdb/HostDB.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/iocore/hostdb/HostDB.cc b/src/iocore/hostdb/HostDB.cc index 12a8532be6..1c0289f149 100644 --- a/src/iocore/hostdb/HostDB.cc +++ b/src/iocore/hostdb/HostDB.cc @@ -1601,23 +1601,22 @@ HostDBRecord::select_best_srv(char *target, InkRand *rand, ts_time now, ts_secon { ink_assert(rr_count <= 0 || static_cast<unsigned int>(rr_count) < hostdb_round_robin_max_count); - int i = 0; int live_n = 0; uint32_t weight = 0, p = INT32_MAX; HostDBInfo *result = nullptr; auto rr = this->rr_info(); // Array of live targets, sized by @a live_n HostDBInfo *live[rr.count()]; - for (auto &target : rr) { + for (auto &rr_target : rr) { // skip down targets. - if (rr[i].is_down(now, fail_window)) { + if (rr_target.is_down(now, fail_window)) { continue; } - if (target.data.srv.srv_priority <= p) { - p = target.data.srv.srv_priority; - weight += target.data.srv.srv_weight; - live[live_n++] = ⌖ + if (rr_target.data.srv.srv_priority <= p) { + p = rr_target.data.srv.srv_priority; + weight += rr_target.data.srv.srv_weight; + live[live_n++] = &rr_target; } else { break; } @@ -1627,7 +1626,8 @@ HostDBRecord::select_best_srv(char *target, InkRand *rand, ts_time now, ts_secon result = this->select_next_rr(now, fail_window); } else { uint32_t xx = rand->random() % weight; - for (i = 0; i < live_n - 1 && xx >= live[i]->data.srv.srv_weight; ++i) { + int i = 0; + for (; i < live_n - 1 && xx >= live[i]->data.srv.srv_weight; ++i) { xx -= live[i]->data.srv.srv_weight; }
