Skip to content

create_waitable_callback causing segmentation fault #18

@tonynajjar

Description

@tonynajjar

Hi @alsora, I recently started seeing this sporadic crash in a node where we use the events executor

nice-2] Stack trace (most recent call last):
[nice-2] #20   Object "", at 0xffffffffffffffff, in 
[nice-2] #19   Object "/code/ros2_ws/build/nav2_controller/controller_server", at 0x55e598ae5684, in _start
[nice-2] #18   Object "/usr/lib/x86_64-linux-gnu/libc.so.6", at 0x7f5488381e3f, in __libc_start_main
[nice-2] #17   Object "/usr/lib/x86_64-linux-gnu/libc.so.6", at 0x7f5488381d8f, in 
[nice-2] #16   Source "/code/ros2_ws/src/navigation2/nav2_controller/src/main.cpp", line 30, in main [0x55e598ae5882]
[nice-2]          27:   auto executor = std::make_shared<rclcpp::executors::EventsExecutor>();
[nice-2]          28: 
[nice-2]          29:   executor->add_node(node->get_node_base_interface());
[nice-2]       >  30:   executor->spin();
[nice-2]          31:   rclcpp::shutdown();
[nice-2]          32: 
[nice-2]          33:   return 0;
[nice-2] #15   Source "/code/ros2_ws/src/irobot_events_executor/irobot_events_executor/src/rclcpp/executors/events_executor/events_executor.cpp", line 74, in spin [0x7f54888622fe]
[nice-2]          71:     ExecutorEvent event;
[nice-2]          72:     bool has_event = events_queue_->dequeue(event);
[nice-2]          73:     if (has_event) {
[nice-2]       >  74:       this->execute_event(event);
[nice-2]          75:     }
[nice-2]          76:   }
[nice-2]          77: }
[nice-2] #14   Source "/code/ros2_ws/src/irobot_events_executor/irobot_events_executor/src/rclcpp/executors/events_executor/events_executor.cpp", line 265, in execute_event [0x7f5488862fe2]
[nice-2]         262:         if (waitable) {
[nice-2]         263:           for (size_t i = 0; i < event.num_events; i++) {
[nice-2]         264:             auto data = waitable->take_data_by_entity_id(event.gen_entity_id);
[nice-2]       > 265:             waitable->execute(data);
[nice-2]         266:           }
[nice-2]         267:         }
[nice-2]         268:         break;
[nice-2] #13   Source "/code/ros2_ws/src/irobot_events_executor/irobot_events_executor/src/rclcpp/executors/events_executor/events_executor_entities_collector.cpp", line 99, in execute [0x7f548884c2df]
[nice-2]          97:   // For all groups registered in the executor, set their event callbacks.
[nice-2]          98:   set_entities_event_callbacks_from_map(weak_groups_associated_with_executor_to_nodes_);
[nice-2]       >  99:   set_entities_event_callbacks_from_map(weak_groups_to_nodes_associated_with_executor_);
[nice-2]         100: }
[nice-2]         101: 
[nice-2]         102: void
[nice-2] #12   Source "/code/ros2_ws/src/irobot_events_executor/irobot_events_executor/src/rclcpp/executors/events_executor/events_executor_entities_collector.cpp", line 182, in set_entities_event_callbacks_from_map [0x7f548884c895]
[nice-2]         179:     if (!node || !group || !group->can_be_taken_from().load()) {
[nice-2]         180:       continue;
[nice-2]         181:     }
[nice-2]       > 182:     set_callback_group_entities_callbacks(group);
[nice-2]         183:   }
[nice-2]         184: }
[nice-2] #11   Source "/code/ros2_ws/src/irobot_events_executor/irobot_events_executor/src/rclcpp/executors/events_executor/events_executor_entities_collector.cpp", line 230, in set_callback_group_entities_callbacks [0x7f548884cf06]
[nice-2]         227:       }
[nice-2]         228:       return false;
[nice-2]         229:     });
[nice-2]       > 230:   group->find_waitable_ptrs_if(
[nice-2]         231:     [this](const rclcpp::Waitable::SharedPtr & waitable) {
[nice-2]         232:       if (waitable) {
[nice-2]         233:         weak_waitables_map_.emplace(waitable.get(), waitable);
[nice-2] #10   Source "/opt/ros/humble/include/rclcpp/rclcpp/callback_group.hpp", line 137, in find_waitable_ptrs_if<rclcpp::executors::EventsExecutorEntitiesCollector::set_callback_group_entities_callbacks(rclcpp::CallbackGroup::SharedPtr)::<lambda(const SharedPtr&)> > [0x7f548884e18d]
[nice-2]         134:   rclcpp::Waitable::SharedPtr
[nice-2]         135:   find_waitable_ptrs_if(Function func) const
[nice-2]         136:   {
[nice-2]       > 137:     return _find_ptrs_if_impl<rclcpp::Waitable, Function>(func, waitable_ptrs_);
[nice-2]         138:   }
[nice-2]         139: 
[nice-2]         140:   RCLCPP_PUBLIC
[nice-2] #9    Source "/opt/ros/humble/include/rclcpp/rclcpp/callback_group.hpp", line 245, in _find_ptrs_if_impl<rclcpp::Waitable, rclcpp::executors::EventsExecutorEntitiesCollector::set_callback_group_entities_callbacks(rclcpp::CallbackGroup::SharedPtr)::<lambda(const SharedPtr&)> > [0x7f548884ebfb]
[nice-2]         242:     std::lock_guard<std::mutex> lock(mutex_);
[nice-2]         243:     for (auto & weak_ptr : vect_ptrs) {
[nice-2]         244:       auto ref_ptr = weak_ptr.lock();
[nice-2]       > 245:       if (ref_ptr && func(ref_ptr)) {
[nice-2]         246:         return ref_ptr;
[nice-2]         247:       }
[nice-2]         248:     }
[nice-2] #8    Source "/code/ros2_ws/src/irobot_events_executor/irobot_events_executor/src/rclcpp/executors/events_executor/events_executor_entities_collector.cpp", line 235, in set_callback_group_entities_callbacks [0x7f548884cdb9]
[nice-2]         232:       if (waitable) {
[nice-2]         233:         weak_waitables_map_.emplace(waitable.get(), waitable);
[nice-2]         234: 
[nice-2]       > 235:         waitable->set_on_ready_callback(
[nice-2]         236:           create_waitable_callback(waitable.get()));
[nice-2]         237:       }
[nice-2]         238:       return false;
[standalone_converter-14] [INFO] [1680268851.997787714] [costmap_converter.costmap_converter]: Standalone costmap converter: costmap_converter::CostmapToPolygonsDBSMCCH loaded.
[nice-2] #7    Source "/opt/ros/humble/include/rclcpp/rclcpp/qos_event.hpp", line 187, in set_on_ready_callback [0x7f5488e6b257]
[nice-2]         184:     // Set it temporarily to the new callback, while we replace the old one.
[nice-2]         185:     // This two-step setting, prevents a gap where the old std::function has
[nice-2]         186:     // been replaced but the middleware hasn't been told about the new one yet.
[nice-2]       > 187:     set_on_new_event_callback(
[nice-2]         188:       rclcpp::detail::cpp_callback_trampoline<const void *, size_t>,
[nice-2]         189:       static_cast<const void *>(&new_callback));
[nice-2] #6    Object "/opt/ros/humble/lib/librclcpp.so", at 0x7f54892392e3, in rclcpp::QOSEventHandlerBase::set_on_new_event_callback(void (*)(void const*, unsigned long), void const*)
[nice-2] #5    Object "/opt/ros/humble/lib/librmw_cyclonedds_cpp.so", at 0x7f5487a3c6f0, in rmw_event_set_callback
[nice-2] #4    Object "/opt/ros/humble/lib/librmw_cyclonedds_cpp.so", at 0x7f5487a53c41, in 
[nice-2] #3    Object "/opt/ros/humble/lib/librclcpp.so", at 0x7f54891ec538, in void rclcpp::detail::cpp_callback_trampoline<void const*, unsigned long, void>(void const*, unsigned long)
[nice-2] #2    Source "/usr/include/c++/11/bits/std_function.h", line 290, in _M_invoke [0x7f548884f707]
[nice-2]         287:       static _Res
[nice-2]         288:       _M_invoke(const _Any_data& __functor, _ArgTypes&&... __args)
[nice-2]         289:       {
[nice-2]       > 290: 	return std::__invoke_r<_Res>(*_Base::_M_get_pointer(__functor),
[nice-2]         291: 				     std::forward<_ArgTypes>(__args)...);
[nice-2]         292:       }
[nice-2] #1    Source "/usr/include/c++/11/bits/invoke.h", line 111, in __invoke_r<void, rclcpp::executors::EventsExecutorEntitiesCollector::create_waitable_callback(void*)::<lambda(size_t, int)>&, long unsigned int, int> [0x7f548884fb45]
[nice-2]         108:       using __type = typename __result::type;
[nice-2]         109:       using __tag = typename __result::__invoke_type;
[nice-2]         110:       if constexpr (is_void_v<_Res>)
[nice-2]       > 111: 	std::__invoke_impl<__type>(__tag{}, std::forward<_Callable>(__fn),
[nice-2]         112: 					std::forward<_Args>(__args)...);
[nice-2]         113:       else
[nice-2]         114: 	return std::__invoke_impl<__type>(__tag{},
[nice-2] #0    Source "/usr/include/c++/11/bits/invoke.h", line 61, in __invoke_impl<void, rclcpp::executors::EventsExecutorEntitiesCollector::create_waitable_callback(void*)::<lambda(size_t, int)>&, long unsigned int, int> [0x7f548884fdf8]
[nice-2]          58:   template<typename _Res, typename _Fn, typename... _Args>
[nice-2]          59:     constexpr _Res
[nice-2]          60:     __invoke_impl(__invoke_other, _Fn&& __f, _Args&&... __args)
[nice-2]       >  61:     { return std::forward<_Fn>(__f)(std::forward<_Args>(__args)...); }
[nice-2]          62: 
[nice-2]          63:   template<typename _Res, typename _MemFun, typename _Tp, typename... _Args>
[nice-2]          64:     constexpr _Res
[nice-2] Segmentation fault (Address not mapped to object [0x1])

Tracing it back I suspected that this commit might be the culprit?

From the information I gave you so far are you able to tell if this commit is causing this crash or not? Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions