Skip to content

destroyed nodes can cause Executor to crash #272

@codebot

Description

@codebot

User error alert! This is probably because I'm still learning C++11 🤕 but I suspect I might not be the only person who tries to do this:

rclcpp::executors::SingleThreadedExecutor executor;
executor.add_node(std::make_shared<MyNodeSubclass>());
executor.spin();

which results in this:

terminate called after throwing an instance of 'std::system_error'
  what():  Invalid argument

with this backtrace:

Thread 1 "minimal_talker" received signal SIGABRT, Aborted.
0x00007ffff6647428 in __GI_raise (sig=sig@entry=6)
    at ../sysdeps/unix/sysv/linux/raise.c:54
54	../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  0x00007ffff6647428 in __GI_raise (sig=sig@entry=6)
    at ../sysdeps/unix/sysv/linux/raise.c:54
#1  0x00007ffff664902a in __GI_abort () at abort.c:89
#2  0x00007ffff6c8084d in __gnu_cxx::__verbose_terminate_handler() ()
   from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3  0x00007ffff6c7e6b6 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4  0x00007ffff6c7e701 in std::terminate() ()
   from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5  0x00007ffff6c7e919 in __cxa_throw ()
   from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6  0x00007ffff6ca77fe in std::__throw_system_error(int) ()
   from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#7  0x0000000000417d03 in std::mutex::lock() ()
#8  0x0000000000418a36 in std::lock_guard<std::mutex>::lock_guard(std::mutex&)
    ()
#9  0x00007ffff79a4ea8 in GuardCondition::attachCondition(std::mutex*, std::condition_variable*) () from /home/mquigley/ros2/install/lib/librmw_fastrtps_cpp.so
#10 0x00007ffff799d7bc in rmw_wait ()
   from /home/mquigley/ros2/install/lib/librmw_fastrtps_cpp.so
#11 0x00007ffff7767026 in rcl_wait ()
   from /home/mquigley/ros2/install/lib/librcl.so
#12 0x00007ffff7439b3e in rclcpp::executor::Executor::wait_for_work(std::chrono::duration<long, std::ratio<1l, 1000000000l> >) ()
   from /home/mquigley/ros2/install/lib/librclcpp.so
#13 0x00007ffff743ad61 in rclcpp::executor::Executor::get_next_executable(std::chrono::duration<long, std::ratio<1l, 1000000000l> >) ()
   from /home/mquigley/ros2/install/lib/librclcpp.so
#14 0x00007ffff7441f45 in rclcpp::executors::single_threaded_executor::SingleThreadedExecutor::spin() () from /home/mquigley/ros2/install/lib/librclcpp.so
#15 0x0000000000417927 in main ()

I'm not sure what the right answer is. If it's possible to somehow generate a warning and say something like "hey there! I hope you're having a gr8 day. You should probably hold a shared_ptr to that instance on your stack." But that might be hard to generate (actually I have no idea how one could generate that).

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingin reviewWaiting for review (Kanban column)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions