-
Notifications
You must be signed in to change notification settings - Fork 845
block_errors: Fix plugin message handling #12757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
block_errors: Fix plugin message handling #12757
Conversation
The msg_hook handler was not verifying the event type and was incorrectly logging errors for messages intended for other plugins. ATS core broadcasts all plugin messages to all registered handlers, so each plugin must filter for its own messages. Added TS_EVENT_LIFECYCLE_MSG check, filter messages by 'block_errors' target prefix, and used TextView to parse target/command.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this bug! The message filtering logic is correct and the test coverage is comprehensive.
Suggestion: We should prefer std::string and std::string_view instead of swoc::TextView. Per PR/issue scrub discussion, if we can easily use STL types we should prefer them over adding dependencies that aren't as well maintained.
Something like:
#include <string>
#include <string_view>
static int
msg_hook(TSCont * /* contp ATS_UNUSED */, TSEvent event, void *edata)
{
if (event != TS_EVENT_LIFECYCLE_MSG) {
TSError("block_errors: unexpected event %d", event);
return TS_EVENT_NONE;
}
TSPluginMsg *msg = static_cast<TSPluginMsg *>(edata);
std::string_view tag{msg->tag};
// Filter for messages meant for this plugin
static constexpr std::string_view PREFIX{"block_errors."};
if (tag.substr(0, PREFIX.size()) != PREFIX) {
Dbg(dbg_ctl, "msg_hook: message for a different plugin: %.*s",
static_cast<int>(tag.size()), tag.data());
return TS_EVENT_NONE;
}
std::string_view command = tag.substr(PREFIX.size());
std::string data{static_cast<const char *>(msg->data), msg->data_size};
Dbg(dbg_ctl, "msg_hook: command=%.*s data=%s",
static_cast<int>(command.size()), command.data(), data.c_str());
if (command == "enabled") {
enabled = static_cast<bool>(std::stoi(data));
} else if (command == "limit") {
RESET_LIMIT = std::stoi(data);
} else if (command == "cycles") {
TIMEOUT_CYCLES = std::stoi(data);
} else if (command == "shutdown") {
shutdown_connection = static_cast<bool>(std::stoi(data));
} else {
Dbg(dbg_ctl, "msg_hook: unknown command '%.*s'",
static_cast<int>(command.size()), command.data());
TSError("block_errors: unknown command '%.*s'",
static_cast<int>(command.size()), command.data());
}
Dbg(dbg_ctl, "reset limit: %d per minute, timeout limit: %d minutes, shutdown connection: %d enabled: %d",
RESET_LIMIT, TIMEOUT_CYCLES, shutdown_connection, enabled);
return TS_EVENT_NONE;
}|
Diff with master: |
bryancall
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a look at the comments on the PR
|
But TextView simplifies the logic. It uses Are we deprecating TextView? If not, we should make use of the API. |
The msg_hook handler was not verifying the event type and was incorrectly logging errors for messages intended for other plugins. ATS core broadcasts all plugin messages to all registered handlers, so each plugin must filter for its own messages. Added TS_EVENT_LIFECYCLE_MSG check, filter messages by 'block_errors' target prefix, and used TextView to parse target/command.