You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@trafficserver.apache.org by "cmcfarlen (via GitHub)" <gi...@apache.org> on 2026/04/30 18:37:44 UTC
[PR] Fix index issue with records in HostDBRecord::select_best_srv [trafficserver]
cmcfarlen opened a new pull request, #13132:
URL: https://github.com/apache/trafficserver/pull/13132
This came up in a copilot review of a fix unrelated to this issue so I created this separate PR to address this.
It seems the loop structure at some point looped over an index, but was changed to a range based loop, neglecting to change one aspect. But it was not noticed because the index variable is declared before the loop.
It does seem like this is a subtle bug since the index variable could be adjusted by the inner loop that increments is, potentially skipping random targets in the list.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix index issue with records in HostDBRecord::select_best_srv [trafficserver]
Posted by "cmcfarlen (via GitHub)" <gi...@apache.org>.
cmcfarlen merged PR #13132:
URL: https://github.com/apache/trafficserver/pull/13132
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix index issue with records in HostDBRecord::select_best_srv [trafficserver]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #13132:
URL: https://github.com/apache/trafficserver/pull/13132#discussion_r3170117059
##########
src/iocore/hostdb/HostDB.cc:
##########
@@ -1610,7 +1609,7 @@ HostDBRecord::select_best_srv(char *target, InkRand *rand, ts_time now, ts_secon
HostDBInfo *live[rr.count()];
for (auto &target : rr) {
// skip down targets.
- if (rr[i].is_down(now, fail_window)) {
+ if (target.is_down(now, fail_window)) {
Review Comment:
The range-for loop variable `target` shadows the output parameter `char *target`, which makes the function harder to read and easier to accidentally misuse. Consider renaming the loop variable (e.g., `rr_target`/`srv_target`) or the output buffer parameter to avoid shadowing.
##########
src/iocore/hostdb/HostDB.cc:
##########
@@ -1627,6 +1626,7 @@ 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;
+ int i = 0;
for (i = 0; i < live_n - 1 && xx >= live[i]->data.srv.srv_weight; ++i) {
Review Comment:
`i` is initialized to 0 at declaration and then immediately re-initialized in the `for` initializer. Consider removing the redundant `i = 0` in the loop header (use `for (; ... )`) to avoid duplication.
```suggestion
for (; i < live_n - 1 && xx >= live[i]->data.srv.srv_weight; ++i) {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org