Skip to content
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

Erase MessageHandler for topics without any registered handlers #229

Merged

Conversation

hikinggrass
Copy link
Contributor

This drastically reduces the amount of lingering threads just hanging around and doing absolutely nothing

This drastically reduces the amount of lingering threads just hanging around and doing absolutely nothing

Signed-off-by: Kai-Uwe Hermann <[email protected]>
if (!found) {
EVLOG_AND_THROW(
EverestInternalError(fmt::format("Internal error: topic '{}' should have a matching handler!", topic)));
EVLOG_warning << fmt::format("Internal error: topic '{}' should have a matching handler!", topic);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not really an error, as is written in the comment, this is an valid but unlikely event.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to a verbose log and slightly reworded the comment


// only subscribe for this topic if we aren't already and the mqtt client is connected
// if we are not connected the on_mqtt_connect() callback will subscribe to the topic
if (this->mqtt_is_connected && this->message_handlers[topic].count_handlers() == 1) {
if (this->mqtt_is_connected && this->message_handlers.at(topic).count_handlers() == 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing this the first time, why should count_handlers() == 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's because if count_handler == 1 after registering a new handler it was the first handler being registered which should then trigger a subscribe

Signed-off-by: Kai-Uwe Hermann <[email protected]>
@hikinggrass hikinggrass merged commit 268115f into main Jan 8, 2025
5 checks passed
@hikinggrass hikinggrass deleted the bugfix/prevent-lingering-threads-from-message-handler branch January 8, 2025 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants