Failed to close DataReader

6 posts / 0 new
Last post
Offline
Last seen: 4 years 4 months ago
Joined: 08/13/2014
Posts: 55
Failed to close DataReader

Hi everybody,

I want to destroy my data reader in some situations while my program is running. To do this, I try " dr = dds::core::null " but it does not solve my problem. I have set my datareader's history QoS to KeepAll(), but I still receive data in my datareader cache and my memory increase (There is not any problem at the usual running of my application since I take the samples from my data reader cache). Is there any QoS like dds::core::policy::Lifespan (which is available for DataWriter) for datareader which destroy samples from datareader cache after a customizable time? 

I also tried to close Datareader with close() function, but I got the following errors;

[D1105|Sub(1A09)|T=NotifyMessage|DELETE Reader]PRESPsService_destroyLocalEndpointWithCursor:!delete read conditions attached
[D1105|Sub(1A09)|T=NotifyMessage|DELETE Reader]PRESPsService_destroyLocalEndpoint:!delete local reader
[D1105|Sub(1A09)|T=NotifyMessage|DELETE Reader]DDS_DataReader_deleteI:!delete PRESLocalEndpoint
[D1105|Sub(1A09)|T=NotifyMessage|DELETE Reader]DDS_Subscriber_delete_datareader:!delete reader
Failed to close DataReader

I would be very appreciated if anyone can help me for solving my problem. Thanks in advance for you help.

Best Regards,

Bonjefir

Fernando Garcia's picture
Offline
Last seen: 4 months 6 days ago
Joined: 05/18/2011
Posts: 199

Hi Bonjefir,

Can you share the code in which you destroy your DataReader. It looks like when your system tries to delete the DataReader it has some read conditions attached.

From your code I assume that you are using the Modern C++ API. We have an example on Github that illustrates how to use ReadConditions with it. However, in that case destructors handle the deletion of all the components in play (i.e., DataWriters, Waitsets, etc.).

Thanks,
Fernando.

Offline
Last seen: 4 years 4 months ago
Joined: 08/13/2014
Posts: 55

Hi Fernando,

I will provide you a sample code in a couple of days. But your assumption about readcontion is true. My code is something as follows:

/// An object for readconditioner handler class
ReadCondHandler readConditionhandler(dr,processData, errorMessage,loopVar,topicName);

readCondition = dds::sub::cond::ReadCondition(dr, dataState,readConditionhandler);

/// An object for guardconditioner class
GuardCondHandler guardCondHandler(escapeVar);

guardCond.trigger_value(false);
guardCond.handler(guardCondHandler);

// A WaitSet is created and readCondition and guardCond is attached to it
waitset = dds::core::cond::WaitSet();

waitset += readCondition;
waitset += guardCond;

Before closing datareader, I detach all conditions from my waitset by calling: 

waitset->detach_all();

But this does not work. Please be informed that if we do not create readcondition then we can close datareader without any problem. What should I do to detach readcondition from my datareader?

Thanks in advance for your help.

Bonjefir

Offline
Last seen: 2 months 2 weeks ago
Joined: 04/02/2013
Posts: 194

Hi,

I think your application may be keeping a reference to the ReadCondition, which retains the DataReader—that would explain why nullifying the 'dr' variable doesn't destroy it. DataReader::close() would also fail because it detects that a related ReadCondition still exists.

Make sure you don't keep references to the ReadCondition. You can also call ReadCondition::close(), but that function was introduced in 5.2.3.

Alex

Offline
Last seen: 4 years 4 months ago
Joined: 08/13/2014
Posts: 55

Hi Alex,

I solved my problem by the following code before closing data reader;

readCondition = dds::sub::cond::ReadCondition(dds::core::null);

I think the close function of readcondition is also doing something like this. Anyway, thanks for your nice helps. (I did not know your company release a new version!!!)

Best Regards,

Bonjefir

 

 

Offline
Last seen: 2 months 2 weeks ago
Joined: 04/02/2013
Posts: 194

The difference between closing and nullifying a variable is that closing forces the destruction of the underlying object, no matter what other references you may have. Assigning dds::core::null decreases the reference count. In your case 'readCondition' was the last reference, so the object was destroyed.

Also, you should be able to simply do this:

readCondition = dds::core::null;

or in C++11:

readCondition = nullptr;

Regards,

Alex