Honor the user holding onto shared_ptrs during subscription callbacks
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 805
- Forks
- 564
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 27
Description
While debugging https://github.com/ros2/rmw_cyclonedds/issues/469 , we found that loaned messages do not properly honor the user holding onto shared_ptrs. In particular, if you look at the code in https://github.com/ros2/rclcpp/blob/126d517193b6df8177680898e23906a85792eaf6/rclcpp/src/rclcpp/executor.cpp#L626-L662 , you can see that the executor always immediately returns the loan to the rmw layer, regardless of whether the user took a shared_ptr reference.
We have worked around this for now by disabling loans by default, but that is not an ideal solution. Instead, what we should do is make a custom destructor for the shared_ptr that we create, which is responsible for returning the loan to the rmw layer. With that in place, we could turn loans back on, and still be safe when users take shared_ptr references.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in rclcpp/src/rclcpp/executor.cpp at lines 626-662 and trace how loaned messages are returned to the rmw layer during subscription callbacks. Verify the shared_ptr lifetime behavior and define done as returning the loan only after the user's final shared_ptr reference is released, while keeping loaned-message use safe.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- distributed-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100