Skip to content

move_group.cpp: seg fault bug fix - #426

Merged
v4hn merged 4 commits into
moveit:indigo-develfrom
gaspers:patch-1
Feb 1, 2017
Merged

v4hn merged 4 commits into
moveit:indigo-develfrom
gaspers:patch-1

Conversation

@gaspers

@gaspers gaspers commented Jan 26, 2017

Copy link
Copy Markdown
Contributor

Description

Fixed a bug with casting CallbackQueueInterface * to ros::CallbackQueue * without a check.
Without this additional check, creating an instance of MoveGroup in a nodelet causes a segmentation fault, because of different CallbackQueue implementations (nodelet::detail::CallbackQueue).

#425

Fixed a bug with casting CallbackQueueInterface * to ros::CallbackQueue * without a check.
moveit#425
@v4hn

v4hn commented Jan 26, 2017

Copy link
Copy Markdown
Contributor

Thank you for the patch! So standard ROS indeed provides another type of callback structure...
I'm sorry, nobody thought of nodelets back then..

I don't really like to rely on RTTI to resolve this, but imo it's roscpp's fault for not exposing a processing-method for the queue via the abstract interface... So I don't see a cleaner way to keep all use-cases working.

I just checked and RTTI is required in core MoveIt already, but this patch will force user-code, i.e. everything using the MoveGroupInterface, to compile with it too. Granted, it's not something you switch-off everyday though..

I approve the patch. This is a plain bugfix and easy enough to understand.
Should be forward-ported to j/k.

@de-vri-es

Copy link
Copy Markdown
Contributor

I'm not familiar with nodelets callback queue / threading model, but don't we run the risk of processing the wrong callback queue using ros::spinOnce()? If so that could potentially lead to race conditions if handlers are fired that the code doesn't except.

Another option may to to explicitly give a callback queue to the action client on construction and process that queue exactly when desired (of which we will know the exact type, since we created it, so also no RTTI required).

Alternatively, if there is no risk of race conditions, is there a reason not to go for ros::spinOnce() in all cases?

@gaspers

gaspers commented Jan 26, 2017

Copy link
Copy Markdown
Contributor Author

ros::spinOnce() was the default before. That was changed by https://github.com/ros-planning/moveit_ros/pull/701 to support specific callbacks, with the problem of dropping nodelet support. That is the reason for not doing ros::spinOnce() in all cases.

@de-vri-es

Copy link
Copy Markdown
Contributor

Right, but then by reverting to ros::spinOnce() we don't support specific callback queues any more if the callback queue is not a ros::CallbackQueue. Of course it's already broken for nodelets as it is, but we should be sure not to introduce possible race conditions.

@v4hn

v4hn commented Jan 26, 2017 via email

Copy link
Copy Markdown
Contributor

@de-vri-es

Copy link
Copy Markdown
Contributor

The patch fixes the recently broken non-ros::CallbackQueue support by reverting to the previous behavior in that case. So this shouldn't break anything that hasn't been broken for years..

Nodelets weren't considered back then. Since this is specifically geared for nodelets it makes sense to look at the implications of that.

However, as far as I can tell from the source, the nodelet manager doesn't even use the default callback queue. It seems to create its own thread pool and manage everything from there. That means the spinOnce() may be a nop in the case of nodelets, but that's not a race condition. And since the nodelets are processing their callback queues in a separate thread pool I don't think it matters that the spinOnce() may not be doing anything.

More importantly, since all the waitForAction calls are in the constructor it should be safe anyway. Any code that is accessing the object before the constructor finished is wrong. So not our problem.

In other words: I think I'm convinced there's no danger of race conditions.

@gaspers

gaspers commented Jan 27, 2017

Copy link
Copy Markdown
Contributor Author

However, as far as I can tell from the source, the nodelet manager doesn't even use the default callback queue. It seems to create its own thread pool and manage everything from there. That means the spinOnce() may be a nop in the case of nodelets, but that's not a race condition. And since the nodelets are processing their callback queues in a separate thread pool I don't think it matters that the spinOnce() may not be doing anything.

Yes, you are right. Nodelets don't need ros::spinOnce() as the nodelet manager handles threads and processes message queues. Additionally, spinOnce() wouldn't help with different CallbackQueue implementations either, I think. SpinOnce() only calls the global CallbackQueue. So perhaps, I should remove the else-block? That would reduce the fix to preventing the broken cast.
In the case of nodelets, we tested the code without spinOnce successfully. In the default case of a global ros::CallbackQueue, the code should work exactly like spinOnce(). That was stated and tested in https://github.com/ros-planning/moveit_ros/pull/701.

@de-vri-es

de-vri-es commented Jan 27, 2017 •

Copy link
Copy Markdown
Contributor

Additionally, spinOnce() wouldn't help with different CallbackQueue implementations either

I think you're right. Maybe we should log a warning instead? Though it is possible that some other thread is already processing the relevant callback queue (like the nodelet queue), in which case the warning would be a bit of a nuisance.

Fixed a bug with casting CallbackQueueInterface * to ros::CallbackQueue * without a check.
moveit#425
@gaspers

gaspers commented Jan 31, 2017

Copy link
Copy Markdown
Contributor Author

I integrated your suggestion, added a comment (for else branch) and tried to find a helpful warning text that is emitted once instead of calling spinOnce().

Fixed a bug with casting CallbackQueueInterface * to ros::CallbackQueue * without a check. 
moveit#425

@de-vri-es de-vri-es left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks goods to me. Thanks! :)

Fixed a bug with casting CallbackQueueInterface * to ros::CallbackQueue * without a check.
moveit#425

@v4hn v4hn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually preferred the previous version with the explicit spinOnce, but @de-vri-es prefers that version and I'm ok with it too.

@v4hn
v4hn merged commit 8ddb57b into moveit:indigo-devel Feb 1, 2017
v4hn pushed a commit that referenced this pull request Feb 1, 2017
Fixed a bug with casting CallbackQueueInterface * to ros::CallbackQueue * without a check.
#425
v4hn pushed a commit that referenced this pull request Feb 1, 2017
Fixed a bug with casting CallbackQueueInterface * to ros::CallbackQueue * without a check.
#425
@v4hn

v4hn commented Feb 1, 2017

Copy link
Copy Markdown
Contributor

Merged and cherry-picked to jade/kinetic. Thank you lots for creating the issue and the patch @gaspers !

@gaspers
gaspers deleted the patch-1 branch February 1, 2017 10:33
@gaspers

gaspers commented Feb 1, 2017

Copy link
Copy Markdown
Contributor Author

Thank you for the fast responses and for including our patch.

JafarAbdi pushed a commit to JafarAbdi/moveit that referenced this pull request Mar 24, 2022
* Add forward_trajectory local solver plugin (moveit#359)
* Use ros2_control based joint simulation and remove unnecessary comment
* Update copyrights
* Restructure hybrid planning package
* Fix formatting and add missing time stamp in local solver plugin
* Remove unnecessary logging and param loading
* Enable different interfaces between local planner and controller
* Use JointGroupPositionController as demo hardware controller
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants