Skip to content
This repository was archived by the owner on Dec 9, 2025. It is now read-only.

Erase MessageHandler for topics without any registered handlers#229

Merged
hikinggrass merged 6 commits intomainfrom
bugfix/prevent-lingering-threads-from-message-handler
Jan 8, 2025
Merged

Erase MessageHandler for topics without any registered handlers#229
hikinggrass merged 6 commits intomainfrom
bugfix/prevent-lingering-threads-from-message-handler

Conversation

@hikinggrass
Copy link
Member

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 <kai-uwe.hermann@pionix.de>
Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
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
Member 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
Member 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 <kai-uwe.hermann@pionix.de>
Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
@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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants