Copilot commented on code in PR #14066:
URL: https://github.com/apache/trafficserver/pull/14066#discussion_r4565985809
##########
src/proxy/HostStatus.cc:
##########
@@ -281,14 +328,23 @@ HostStatus::setHostStatus(const std::string_view name,
TSHostStatus status, cons
host_stat->status = status;
Dbg(dbg_ctl_host_statuses, "reasons: %d, status: %s",
host_stat->reasons, HostStatusNames[host_stat->status]);
}
+ effective_status = host_stat->status;
+ remaining_reasons = host_stat->reasons;
}
- // log it.
- if (status == TSHostStatus::TS_HOST_STATUS_DOWN) {
- Note("Host %.*s has been marked down, down_time: %d - %s.",
int(name.size()), name.data(), down_time,
- down_time == 0 ? "indefinitely." : "seconds.");
+ // An UP request clears one reason; the host recovers only when none remain.
+ auto reason_name = Reason::getReasonName(reason);
+ if (status == TSHostStatus::TS_HOST_STATUS_DOWN && down_time == 0) {
+ Note("Host %.*s has been marked down, down_time: indefinitely, reasons:
%s.", int(name.size()), name.data(),
+ reason_name.c_str());
+ } else if (status == TSHostStatus::TS_HOST_STATUS_DOWN) {
+ Note("Host %.*s has been marked down, down_time: %u seconds, reasons:
%s.", int(name.size()), name.data(), down_time,
Review Comment:
The log format string uses `%u` for `down_time`, but the previous code used
`%d` (suggesting `down_time` is signed). A mismatched printf format specifier
is undefined behavior. Recommendation: align the format specifier with
`down_time`'s actual type (e.g., switch back to `%d` if it is `int`, or cast to
the correct unsigned type / use an appropriate fixed-width format macro if it
is unsigned).
##########
src/proxy/HostStatus.cc:
##########
@@ -281,14 +328,23 @@ HostStatus::setHostStatus(const std::string_view name,
TSHostStatus status, cons
host_stat->status = status;
Dbg(dbg_ctl_host_statuses, "reasons: %d, status: %s",
host_stat->reasons, HostStatusNames[host_stat->status]);
}
+ effective_status = host_stat->status;
+ remaining_reasons = host_stat->reasons;
}
- // log it.
- if (status == TSHostStatus::TS_HOST_STATUS_DOWN) {
- Note("Host %.*s has been marked down, down_time: %d - %s.",
int(name.size()), name.data(), down_time,
- down_time == 0 ? "indefinitely." : "seconds.");
+ // An UP request clears one reason; the host recovers only when none remain.
+ auto reason_name = Reason::getReasonName(reason);
+ if (status == TSHostStatus::TS_HOST_STATUS_DOWN && down_time == 0) {
+ Note("Host %.*s has been marked down, down_time: indefinitely, reasons:
%s.", int(name.size()), name.data(),
+ reason_name.c_str());
+ } else if (status == TSHostStatus::TS_HOST_STATUS_DOWN) {
+ Note("Host %.*s has been marked down, down_time: %u seconds, reasons:
%s.", int(name.size()), name.data(), down_time,
+ reason_name.c_str());
Review Comment:
For DOWN transitions, the message label `reasons:` currently prints the
requested mask (`reason`), not the effective post-update mask in the record
(`remaining_reasons`). If the host already had other reason bits set, this log
line can be misleading for operators. Recommendation: either log the effective
reasons (using `remaining_reasons`) or rename the field to make it explicit
(e.g., `requested reasons:`) and optionally include both requested + effective.
##########
src/proxy/HostStatus.cc:
##########
@@ -281,14 +328,23 @@ HostStatus::setHostStatus(const std::string_view name,
TSHostStatus status, cons
host_stat->status = status;
Dbg(dbg_ctl_host_statuses, "reasons: %d, status: %s",
host_stat->reasons, HostStatusNames[host_stat->status]);
}
+ effective_status = host_stat->status;
+ remaining_reasons = host_stat->reasons;
}
- // log it.
- if (status == TSHostStatus::TS_HOST_STATUS_DOWN) {
- Note("Host %.*s has been marked down, down_time: %d - %s.",
int(name.size()), name.data(), down_time,
- down_time == 0 ? "indefinitely." : "seconds.");
+ // An UP request clears one reason; the host recovers only when none remain.
+ auto reason_name = Reason::getReasonName(reason);
+ if (status == TSHostStatus::TS_HOST_STATUS_DOWN && down_time == 0) {
+ Note("Host %.*s has been marked down, down_time: indefinitely, reasons:
%s.", int(name.size()), name.data(),
+ reason_name.c_str());
+ } else if (status == TSHostStatus::TS_HOST_STATUS_DOWN) {
+ Note("Host %.*s has been marked down, down_time: %u seconds, reasons:
%s.", int(name.size()), name.data(), down_time,
+ reason_name.c_str());
+ } else if (effective_status == TSHostStatus::TS_HOST_STATUS_UP) {
+ Note("Host %.*s has been marked up, cleared reasons: %s.",
int(name.size()), name.data(), reason_name.c_str());
} else {
- Note("Host %.*s has been marked up.", int(name.size()), name.data());
+ Note("Host %.*s is still down, cleared reasons: %s, remaining reasons:
%s.", int(name.size()), name.data(), reason_name.c_str(),
+ Reason::getReasonName(remaining_reasons).c_str());
Review Comment:
This builds a temporary `std::string` via
`Reason::getReasonName(remaining_reasons)` and immediately takes `c_str()` in
the call expression. While the pointer is valid for the duration of the full
expression, it’s easy to misread and makes debugging harder. Recommendation:
store the remaining-reasons string in a local variable (similar to
`reason_name`) and pass its `c_str()` to `Note`.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]