Skip to content

Commit

Permalink
Fix data race on 'on_parameter_event'
Browse files Browse the repository at this point in the history
The callback 'on_parameter_event' was internally
accessing node_base_, which could be already destroyed.

This commit stores the node name, which is what
the callback wants to know, so we don't have to
access the node to obtain it.
  • Loading branch information
Mauro Passerino committed Oct 10, 2023
1 parent 0719ef5 commit 7d9f7e6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions rclcpp/include/rclcpp/time_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ class TimeSource
// Store (and update on node attach) logger for logging.
Logger logger_;

// Fully qualified node name
const char * node_name_;

// QoS of the clock subscription.
rclcpp::QoS qos_;

Expand Down
3 changes: 2 additions & 1 deletion rclcpp/src/rclcpp/time_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ void TimeSource::attachNode(
node_parameters_ = node_parameters_interface;
// TODO(tfoote): Update QOS

node_name_ = node_base_->get_fully_qualified_name();
logger_ = node_logging_->get_logger();

// Though this defaults to false, it can be overridden by initial parameter values for the node,
Expand Down Expand Up @@ -297,7 +298,7 @@ void TimeSource::destroy_clock_sub()
void TimeSource::on_parameter_event(const rcl_interfaces::msg::ParameterEvent::SharedPtr event)
{
// Filter out events on 'use_sim_time' parameter instances in other nodes.
if (event->node != node_base_->get_fully_qualified_name()) {
if (event->node != node_name_) {
return;
}
// Filter for only 'use_sim_time' being added or changed.
Expand Down

0 comments on commit 7d9f7e6

Please sign in to comment.