-
Notifications
You must be signed in to change notification settings - Fork 125
Description
On the PR ros2/rclcpp#2624 I provide a fix to allow the user to make copies of loaned messages, keeping them beyond the subscription callback scope. With the fix, the loaned message is returned to the DDS when the user's copy of the message goes out of scope.
In the PR I add a unit test to verify that memory is not reused until all entities have returned the loan.
The tests fully pass when history memory policy is set as DYNAMIC_REUSABLE
, but fails when set as PREALLOCATED_WITH_REALLOC
:
[ FAILED ] 2 tests, listed below:
[ FAILED ] TestSharedMemory.user_is_last_loan_owner
[ FAILED ] TestSharedMemory.sub_is_last_loan_owner
The failures mean that a user is provided with loaned memory which has been previously provided, and is still in use:
- Case 1: The user keeps copies (loaned not returned)
- Case 2: A not-spinning subscription is keeping copies in its internal buffer.
While a temporary solution would be to only use DYNAMIC_REUSABLE
on shared memory, this mode has the issue that a undesired copy is performed on a multi-process system, as I describe in #782
So in short:
PREALLOCATED_WITH_REALLOC: Issues shared memory still in use
DYNAMIC_REUSABLE: A copy of the message happens on a multi-process system
Do you think this is a bug, or the use of PREALLOCATED_WITH_REALLOC
inherently breaks proper shared memory management?