Skip to content

Commit ad171bd

Browse files
committed
fix: subscriber callback not removed
* Updated remove_subscriber implementation to use reference when erasing callback from list to ensure that it is properly erased from the shared state * Added some warnings if removal occurs when topic or component are not found
1 parent 197249f commit ad171bd

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

components/event_manager/src/event_manager.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ bool EventManager::remove_subscriber(const std::string &topic, const std::string
120120
{
121121
std::lock_guard<std::recursive_mutex> lk(events_mutex_);
122122
if (!events_.subscribers.contains(topic)) {
123+
logger_.warn("Cannot remove subscriber, there are no subscribers for topic '{}'", topic);
123124
// there is no publisher for this topic
124125
return false;
125126
}
@@ -128,6 +129,8 @@ bool EventManager::remove_subscriber(const std::string &topic, const std::string
128129
auto elem = std::find(std::begin(topic_subscribers), std::end(topic_subscribers), component);
129130
bool exists = elem != std::end(topic_subscribers);
130131
if (!exists) {
132+
logger_.warn("Cannot remove subscriber, '{}' is not registered as a subscriber for topic '{}'",
133+
component, topic);
131134
// component is not registered as a subscriber, so return false
132135
return false;
133136
}
@@ -138,7 +141,7 @@ bool EventManager::remove_subscriber(const std::string &topic, const std::string
138141
// remove from `subscriber_callbacks_`
139142
{
140143
std::lock_guard<std::recursive_mutex> lk(callbacks_mutex_);
141-
auto callbacks = subscriber_callbacks_[topic];
144+
auto& callbacks = subscriber_callbacks_[topic];
142145

143146
auto is_component = [&component](std::pair<std::string, event_callback_fn> &e) {
144147
return std::get<0>(e) == component;

0 commit comments

Comments
 (0)