Skip to content

Commit 80cc919

Browse files
Janosch MachowinskiJanosch Machowinski
authored andcommitted
fix: Call timer->call() from the execution context, not the timer manager
This code was copied straight from the executor and seems to be a workaround for the multithreaded executor, that breaks in this use case. The correct solution for us is to do the timer->call() from within the worker thread. This fixes a deadlock due to double acquisition of an internal lock within the timer manager. Signed-off-by: Janosch Machowinski <J.Machowinski@cellumation.com>
1 parent 11d733c commit 80cc919

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

rclcpp/src/rclcpp/executors/events_cbg_executor/ready_entity.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,18 @@ struct ReadyEntity
7474
if (!shr_ptr) {
7575
return std::function<void()>();
7676
}
77-
auto data = shr_ptr->call();
78-
if (!data) {
79-
// timer was cancelled, skip it.
80-
return std::function<void()>();
81-
}
8277

83-
return [shr_ptr = std::move(shr_ptr), data = std::move(data),
78+
return [shr_ptr = std::move(shr_ptr),
8479
timer_executed_cb = entity.timer_was_executed]() {
80+
auto data = shr_ptr->call();
81+
if (!data) {
82+
// timer was cancelled, skip it.
83+
return;
84+
}
85+
8586
rclcpp::executors::EventsCBGExecutor::execute_timer(shr_ptr, data);
8687

87-
// readd the timer to the timers manager
88+
// readd the timer to the timers manager
8889
timer_executed_cb();
8990
};
9091
} else if constexpr (std::is_same_v<T, rclcpp::ServiceBase::WeakPtr>) {

0 commit comments

Comments
 (0)