Skip to content

bond::Bond constructs TimerBase in its destructor, making it difficult to destruct after rclcpp::shutdown #92

@mmattb

Description

@mmattb

The Bond destructor constructs a TimerBase:

 0# rclcpp::TimerBase::TimerBase(std::shared_ptr<rclcpp::Clock>, std::chrono::duration<long, std::ratio<1l, 1000000000l> >, std::shared_ptr<rclcpp::Context>) in /home/mbryan/Projects/ros/ros2_rolling/install/rclcpp/lib/librclcpp.so
 1# bond::Bond::deadpublishingTimerReset() in /opt/ros/rolling/lib/libbondcpp.so
 2# SM_Alive::Die(BondSMContext&) in /opt/ros/rolling/lib/libbondcpp.so
 3# bond::Bond::breakBond() in /opt/ros/rolling/lib/libbondcpp.so
 4# bond::Bond::~Bond() in /opt/ros/rolling/lib/libbondcpp.so
 5# nav2_util::LifecycleNode::~LifecycleNode() in /home/mbryan/Projects/ros/navigation2/install/nav2_util/lib/libnav2_util_core.so
 6# behavior_server::BehaviorServer::~BehaviorServer() in /home/mbryan/Projects/ros/navigation2/install/nav2_behaviors/lib/libbehavior_server_core.so
 7# std::_Sp_counted_ptr_inplace<behavior_server::BehaviorServer, std::allocator<behavior_server::BehaviorServer>, (__gnu_cxx::_Lock_policy)2>::_M_dispose() in /home/mbryan/Projects/ros/navigation2/install/nav2_behaviors/lib/nav2_behaviors/behavior_server
 8# std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release() in /home/mbryan/Projects/ros/navigation2/install/nav2_behaviors/lib/nav2_behaviors/behavior_server
 9# 0x000055F5FE8BB964 in /home/mbryan/Projects/ros/navigation2/install/nav2_behaviors/lib/nav2_behaviors/behavior_server
10# 0x00007FA05CCD9D90 in /lib/x86_64-linux-gnu/libc.so.6
11# __libc_start_main in /lib/x86_64-linux-gnu/libc.so.6
12# 0x000055F5FE8BBA35 in /home/mbryan/Projects/ros/navigation2/install/nav2_behaviors/lib/nav2_behaviors/behavior_server

Unfortunately this means that we hit exceptions if destruction happens after rclcpp::shutdown is called. Basically this exception translates to "why are you trying to make timer stuff after shutdown?"

[43.062857] (nav2_system_tests) StdoutLine: {'line': b'9: [behavior_server-10] [INFO] [1673598507.589703428] [behavior_server]: Destroying\n'}
[43.062996] (nav2_system_tests) StdoutLine: {'line': b"9: [behavior_server-10] terminate called after throwing an instance of 'rclcpp::exceptions::RCLError'\n"}
[43.063104] (nav2_system_tests) StdoutLine: {'line': b"9: [behavior_server-10]   what():  Couldn't initialize rcl timer handle: the given context is not valid, either rcl_init() was not called or rcl_shutdown() was called., at ./src/rcl/guard_condition.c:67\n"}

Construction for the purpose of doing some operation in a destruction path is not insane per se, but this particular one is requiring us to get careful with shutdown callbacks blah blah in the Nav2 code. It would be good to avoid it if possible.

I don't see deadpublishingTimerReset in today's code base, so I'm not sure what versions of libbond this may affect. Having said that: this is affecting today's Nav2 system tests. Not sure what version those CI rigs are running... The version in the stack above is from the Ubuntu 22.04 repository I believe.

Filed per request of Steve Macenski (who I can't tag for some reason).

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