From 696c22e618bc14203101631f7be6c9f8025f805b Mon Sep 17 00:00:00 2001 From: Skyler Medeiros Date: Sat, 22 Aug 2026 19:14:47 -0700 Subject: [PATCH 1/2] put in_queue under ready_callback_groups_mutex Signed-off-by: Skyler Medeiros --- .../rclcpp/executors/events_cbg_executor/scheduler.hpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/rclcpp/src/rclcpp/executors/events_cbg_executor/scheduler.hpp b/rclcpp/src/rclcpp/executors/events_cbg_executor/scheduler.hpp index 7e924d7de5..48cb018af3 100644 --- a/rclcpp/src/rclcpp/executors/events_cbg_executor/scheduler.hpp +++ b/rclcpp/src/rclcpp/executors/events_cbg_executor/scheduler.hpp @@ -230,11 +230,13 @@ class CBGScheduler */ void callback_group_ready(CallbackGroupHandle *handle, bool callback_group_was_idle) { - if (!handle->in_queue) { + { std::lock_guard l(ready_callback_groups_mutex); - ready_callback_groups.push_back(handle); - handle->in_queue = true; + if (!handle->in_queue) { + ready_callback_groups.push_back(handle); + handle->in_queue = true; + } } if(callback_group_was_idle) { From 4a780fe0c9bddda9de293ef607aef408a0062093 Mon Sep 17 00:00:00 2001 From: Skyler Medeiros Date: Sat, 22 Aug 2026 20:34:36 -0700 Subject: [PATCH 2/2] only remove from ready_callback_groups if in the queue Signed-off-by: Skyler Medeiros --- .../rclcpp/executors/events_cbg_executor/scheduler.hpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/rclcpp/src/rclcpp/executors/events_cbg_executor/scheduler.hpp b/rclcpp/src/rclcpp/executors/events_cbg_executor/scheduler.hpp index 48cb018af3..6fe052bec0 100644 --- a/rclcpp/src/rclcpp/executors/events_cbg_executor/scheduler.hpp +++ b/rclcpp/src/rclcpp/executors/events_cbg_executor/scheduler.hpp @@ -13,6 +13,7 @@ // limitations under the License. #pragma once +#include #include #include #include @@ -214,8 +215,12 @@ class CBGScheduler void remove_callback_group(const CallbackGroupHandle *callback_handle) { std::lock_guard lk(ready_callback_groups_mutex); - ready_callback_groups.erase(std::find(ready_callback_groups.begin(), - ready_callback_groups.end(), callback_handle)); + + auto cbg_it = std::find(ready_callback_groups.begin(), + ready_callback_groups.end(), callback_handle); + if (cbg_it != ready_callback_groups.end()) { + ready_callback_groups.erase(cbg_it); + } callback_groups.remove_if([&callback_handle] (const auto & e) { return e.get() == callback_handle;