Skip to content

Conversation

@saikishor
Copy link
Member

@saikishor saikishor commented Oct 7, 2025

Earlier we were using the objects directly instead of the pointers, and that means inorder for the controllers to have access the onyl way is to store the reference to that particular variable

However, In the new approach with the pointers, we cannot have the reference to the internal memory of the pointers, it is dangerous as in previous case that the loaned interfaces have access to data without having the ownership, this means if everyone removes this interface, we will have a dangling interface

@saikishor saikishor added backport-jazzy Triggers PR backport to ROS 2 jazzy. backport-kilted Triggers PR backport to ROS 2 kilted. labels Oct 7, 2025
@saikishor saikishor removed the backport-jazzy Triggers PR backport to ROS 2 jazzy. label Oct 7, 2025
Copy link
Contributor

@christophfroehlich christophfroehlich left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for adding the explanation why we should change this.

I was just wondering if we should check the use_count when accessing the handle (if there exists even a hardware with it), but I don't know if this is an expensive operation.

@destogl
Copy link
Member

destogl commented Nov 12, 2025

I have here also a question: why is it not also ported to jazzy?

In Jazzy, we faced an issue where we lost some references to handles when trying to access them from JTB. Did you ever encounter this? Can this be related?

@destogl
Copy link
Member

destogl commented Nov 12, 2025

@saikishor can you please explain one more time, I am reading this for the 10th time and I am not sure when this can happen. I is important as I think that i happens for us. But I am not sure why.

Copy link
Member Author

@saikishor saikishor left a comment

Choose a reason for hiding this comment

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

I think the right approach here could be a weak_ptr

@destogl
Copy link
Member

destogl commented Nov 12, 2025

But when can it happen that we have dangling pointer (reference)?

@saikishor
Copy link
Member Author

But when can it happen that we have dangling pointer (reference)?

It could be that if a controller ends up in error and we have to deactivate it and then the chained controllers will be left with an invalid reference, and the consequence of that is pretty unknown. This won't happen if things are handled properly, but we never know the edge cases.

If everyone wanted to keep it this way, I'm fine too

@mamueluth
Copy link
Member

I would also rather use a weak pointer and check if the observed object is still there (command_interface_.lock() before access to the interface) because loaned interfaces do not own but observe the object. By using shared_ptr we increase the reference count and extend live time of the object and i am not sure of the consequences here...

For me it seems like we have more of a lifetime and ownership problem here because a loanedinterfaces should not outlive the interfaces they are created on.

@saikishor
Copy link
Member Author

I would also rather use a weak pointer and check if the observed object is still there (command_interface_.lock() before access to the interface) because loaned interfaces do not own but observe the object. By using shared_ptr we increase the reference count and extend live time of the object and i am not sure of the consequences here...

For me it seems like we have more of a lifetime and ownership problem here because a loanedinterfaces should not outlive the interfaces they are created on.

Yes, I agree with you. Weak_ptr is perfect for this application, but at the same time. I'm worried about the performance costs it might bring. As weak_ptr is lock free but not wait free, so continuous writing to interfaces might cause issues.

I'll see if I can test this on TALOS and see if it causes any jitter or not. This can wait until then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-kilted Triggers PR backport to ROS 2 kilted.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants