Replies: 6 comments 6 replies
-
I am going to move this issue to the Ideas discussion forum. According to the CONTRIBUTING guidelines feature requests and improvements are discussed in that forum. |
Beta Was this translation helpful? Give feedback.
-
Hi, We're experiencing the same issue:
I don't really see a way around this, given the current APIs. I don't understand why eProsima decided to go in this direction: if the factory is a singleton, why not assume that an application is well-behaved and will destroy all its objects properly? If I may suggest: destroy all the impls as you do today -- but don't destroy the participants. Instead, reset all participants' Thanks. P.S.: I opened PR #2739 which can help with this |
Beta Was this translation helpful? Give feedback.
-
Hi @maloel,
Regarding the suggestion of leaving the DDS entity's destruction to the user: although the DDS PIM API returns the DDS object, the ownership is not pass to the user, but it is kept in Fast DDS. Therefore, the application architecture must ensure that the DomainParticipants are deleted before the factory is destroyed. Otherwise, memory will leak because the factory destructor only destroys the DomainParticipantImpl. Once the factory is destroyed, it is not possible to access its API without instantiating a new singleton which no longer has access to the DDS entities created with the previous singleton. So it is not possible to destroy a DomainParticipant once the factory has been destroyed. Also, if the memory has been reserved by Fast DDS, it makes sense that Fast DDS takes charge of freeing it. Leaving the responsibility to the user is not advisable and assuming that an application is well-behaved is sometimes a large assumption. This is a well-known limitation of the DDS PIM API that requires that the user application follows the correct destruction order. |
Beta Was this translation helpful? Give feedback.
-
Hi @JLBuenoLopez-eProsima I wasn't suggesting that the user be responsible for freeing the memory. But the specification does define a This operation crashes on destruction with the eProsima implementation, and I don't see that in the specification anywhere. Your insistence that the user application follow a certain destruction order is impossible to implement, as that order is undefined between different translation-units. At the current state of your code, it is impossible to know whether the participant (or really, the factory) is alive or not. Our code can only blindly |
Beta Was this translation helpful? Give feedback.
-
I would say that the following code would ensure the factory is destroyed after your global object, if it is the only place where struct GlobalObject
{
GlobalObject()
{
dds_factory_ = DomainParticipantFactory::get_instance();
dds_participant_ = dds_factory_->create_participant(....);
}
~GlobalObject()
{
dds_factory_->delete_participant(dds_participant_);
}
private:
DomainParticipantFactory* dds_factory_ = nullptr;
DomainParticipant* dds_participant_ = nullptr;
}; If you cannot architect your application that way, we could refactor DomainParticipantFactory to have a Thoughts? |
Beta Was this translation helpful? Give feedback.
-
@maloel @ivanpauno I have just created #2894 adding |
Beta Was this translation helpful? Give feedback.
-
In ros2, we're migrating from creating one
Participant
perNode
to one perContext
(see ros2/rmw_fastrtps#312).The default context has for example static storage.
The destructor of that object, ends up calling: https://github.com/eProsima/Fast-RTPS/blob/a181a67b94e88839755e83a52ec72af4c9145ac6/include/fastrtps/Domain.h#L145
As the
Domain
object is a singleton, and destruction order of static objects in different transitional units can't be ensured, it sometimes crash (because it's used an already destructedDomain
).I didn't try, but the same bug can happen with https://github.com/eProsima/Fast-RTPS/blob/master/include/fastdds/dds/domain/DomainParticipantFactory.hpp.
And AFAIK, the same problem is common in other DDS vendors.
Expected Behavior
Have a way to construct/destroy Participants in objects with static storage.
Current Behavior
It's not possible.
Steps to Reproduce
I don't have a simple repro ....
I can share detailed steps if needed.
System information
Additional context
The only solution that I have in mind, is to provide a way to the user to create a
Domain
(orDomainParticipantFactory
). In that way, the object can be stored in another transitional unit and destruction order can be ensured. The solution to the commented ROS 2 problem is still complicated, but possible if that's available.We're also considering to stop having a default context, but I just want to rise awareness to the issue.
Beta Was this translation helpful? Give feedback.
All reactions