Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

execute() and stop() both call spin_some(), thus crash #1127

Closed
galou opened this issue Mar 18, 2022 · 5 comments
Closed

execute() and stop() both call spin_some(), thus crash #1127

galou opened this issue Mar 18, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@galou
Copy link
Contributor

galou commented Mar 18, 2022

Description

Despite #503 and #506, you cannot call MoveGroupInterface::stop() in a separate thread while MoveGroupInterface::execute() is running. This is related to thread-safety but I couldn't find information about thread-safety of MoveGroupInterface.

Your environment

  • ROS Distro: Galactic
  • OS Version: Ubuntu 20.04
  • Source build, branch main (419db3b).

Steps to reproduce

Call move_group->execute(), then, before execute returns, call move_group->stop() in another thread.

Expected behaviour

The executable should not crash and the trajectory execution should stop.

Actual behaviour

The executable crashes with

terminate called after throwing an instance of 'std::runtime_error'
what():  Node has already been added to an executor.

Backtrace or Console output

Backtrace.

@galou galou added the bug Something isn't working label Mar 18, 2022
@galou
Copy link
Contributor Author

galou commented Mar 18, 2022

Please note that I'm willing to fix this myself (in the range of my knowledge of MoveIt) but I don't know exactly which strategy to use. I even think that this should be solved in rclcpp to allow calling spin_some() concurrently.

@henningkayser
Copy link
Member

@galou I think the MoveGroupInterface was never designed to be thread-safe, and I don't think there is a good way to make the full API work reliably across multiple threads. What you can do is to use MoveGroupInterface::asyncExecute() for your use case. However, I agree that spinning should not be implemented explicitly inside MGI, but removing all spin calls is a somewhat bigger effort. Would you be interested in working on that?

@galou
Copy link
Contributor Author

galou commented Mar 22, 2022

I can work on it but I have a question first. Why is there a call to spin_some() in MoveGroupInterface::stop()? Are there some callbacks involved? stop() just contains a call to publish().

My suggestion would be to add a std::atomic_bool is_spinning_ member variable and use it to conditionally call spin_some(). Would it be OK?

@henningkayser
Copy link
Member

@galou #1305 should fix this bug. Could you verify and close this issue?

@henningkayser
Copy link
Member

spin_some has been removed a while ago, closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants