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

Fix seg fault in SetRemovedComponentsMsgs when TransformControl tool is used #495

Merged

Conversation

mrushyendra
Copy link
Contributor

@mrushyendra mrushyendra commented Dec 17, 2020

_msg.mutable_entities() need not necessarily contain the _entity as a key when SetRemovedComponentsMsgs() is called, for instance in AddEntityToMessage(). In the case where _entity has no components in entityComponents that changed, but does have some removed Components in removedComponents, this could lead to a seg fault when AddEntityToMessage calls SetRemovedComponentsMsgs.

Secondly, this is only tangentially related, but it looks like AddEntityToMessage also takes a list of component types _types:
https://github.com/ignitionrobotics/ign-gazebo/blob/2f7f33d4fa34657badec81558d5953fe7643769f/src/EntityComponentManager.cc#L849-L851

But this is currently ignored in the call to SetRemovedComponentMsgs. I was wondering if that was intentional, or if it should be modified as well?

Fixes #483

@github-actions github-actions bot added the 🔮 dome Ignition Dome label Dec 17, 2020
@mrushyendra mrushyendra force-pushed the fix_remove_component_msg_segfault branch from 17e79ac to 6afa9eb Compare December 17, 2020 04:20
Copy link
Contributor

@iche033 iche033 left a comment

Choose a reason for hiding this comment

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

confirmed that this fixed the issue.

As for the second point, is the idea for passing in _types to skip adding components to the msg if they are not in _types?

src/EntityComponentManager.cc Outdated Show resolved Hide resolved
@mrushyendra
Copy link
Contributor Author

As for the second point, is the idea for passing in _types to skip adding components to the msg if they are not in _types?

Yeah, that's what I meant

Copy link
Member

@luca-della-vedova luca-della-vedova left a comment

Choose a reason for hiding this comment

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

Just for another data point it also fixes the issue in our simulations

@iche033
Copy link
Contributor

iche033 commented Dec 21, 2020

As for the second point, is the idea for passing in _types to skip adding components to the msg if they are not in _types?

Yeah, that's what I meant

I see. I'm not sure if we should apply the filter to removed components or not actually. Maybe @chapulina or @azeey may have a better idea?

@azeey
Copy link
Contributor

azeey commented Dec 23, 2020

SetRemovedComponentMsgs was added as a refactor of the component removal code in AddEntityToMessage. While the code was inside AddEntityToMessage, the entity would have been added to the message by the time it got to add removed components. So the fix in this PR is appropriate.

But this is currently ignored in the call to SetRemovedComponentMsgs. I was wondering if that was intentional, or if it should be modified as well?

I don't believe it was intentional. I think adding the filter would be a good idea.

@mrushyendra
Copy link
Contributor Author

Just added the filter as well

Copy link
Contributor

@iche033 iche033 left a comment

Choose a reason for hiding this comment

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

the latest changes look good to me

@chapulina chapulina requested a review from azeey January 11, 2021 19:37
Copy link
Contributor

@chapulina chapulina left a comment

Choose a reason for hiding this comment

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

All changes look good to me. I hope no users were expecting the _types filter not to be applied to the removed components, because that would break their expectation.

Do you think you could add some tests to check that the removed types are filtered correctly, @mrushyendra ? It would also be great to add a test for the situation where SetRemovedComponentsMsgs is called on an entity that doesn't have changed components.

Thanks!

Copy link
Contributor

@azeey azeey left a comment

Choose a reason for hiding this comment

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

LGTM! I agree with @chapulina, tests would be great!

Verifies the message created in situations where components are only
removed but not changed, and when a list of types to filter is passed to
the function.

Signed-off-by: Maganty Rushyendra <[email protected]>
@mrushyendra mrushyendra force-pushed the fix_remove_component_msg_segfault branch from 9b66519 to 8164cd5 Compare February 1, 2021 23:58
@mrushyendra
Copy link
Contributor Author

Added a couple of tests

Copy link
Contributor

@azeey azeey left a comment

Choose a reason for hiding this comment

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

CI fails on macOS with the error

9: /Users/jenkins/workspace/ignition_gazebo-ci-pr_any-homebrew-amd64/ign-gazebo/src/EntityComponentManager_TEST.cc:2337: Failure
9: Expected equality of these values:
9:   e1Msg.components().size()
9:     Which is: 0
9:   1u
9:     Which is: 1
  9/156 Test   #9: UNIT_EntityComponentManager_TEST .....................***Exception: SegFault 14.53 sec
test 10

I've left comments to change EXPECT_EQ to ASSERT_EQ, but I'm not sure why the test failed.

src/EntityComponentManager_TEST.cc Outdated Show resolved Hide resolved
src/EntityComponentManager_TEST.cc Outdated Show resolved Hide resolved
@mrushyendra
Copy link
Contributor Author

The tests should be passing now. Had to change the removedComponents traversal to make use of equal_range, instead of using find, since the latter may not return an iterator to the first matching value in the multimap:
https://github.com/ignitionrobotics/ign-gazebo/blob/a82ab6d2c82b1b8858bab746540b4fc21b9aacf9/src/EntityComponentManager.cc#L794-L795

@iche033
Copy link
Contributor

iche033 commented Feb 8, 2021

#482 and #614 are affected by the crash so it would be nice to get this in

@iche033 iche033 closed this Feb 8, 2021
@iche033 iche033 reopened this Feb 8, 2021
@adlarkin adlarkin self-requested a review February 8, 2021 21:17
@adlarkin
Copy link
Contributor

adlarkin commented Feb 8, 2021

All tests are passing now (the only failure for macOS is for INTEGRATION_scene_broadcaster_system, which is unrelated to this PR). I am merging this.

@adlarkin adlarkin merged commit 766bb23 into gazebosim:ign-gazebo4 Feb 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔮 dome Ignition Dome
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Segmentation fault when using TransformControl tool in crowded worlds
6 participants