Comments (6)
We already had similar problems with other services, e.g. for the rosservice
service (see orocos/rtt_ros_integration#60). It would be certainly better to use weak pointers for the parent to break the loop, but normally destruction works fine because the TaskContext destructor actively clears the tasks services in TaskContext.cpp:135.
However, there are many reasons why other shared pointers to a service might still exist and the service is not destroyed, e.g. when there is a CORBA TaskContextProxy.
from rtt.
It seems there may be two causes:
-
Method
clear()
in Service.cpp:219 is not recursive.removeService()
is called for each subservice, but it simply reset shared pointers and does not callclear() on corresponding Services. So if any of subservices has its own subservice we have
shared_ptr` loop.But it does not explain why my example is working properly.
-
Another possible cause is
shared_from_raw()
: Service.hpp:109. It seems there are many pitfalls related with this method: http://stackoverflow.com/questions/22184772/why-is-boostenable-shared-from-raw-so-undocumentedI tried to replace
shared_ptr parent
byweak_ptr parent
inService.hpp
and it did not solve problem. But after I usedService * parent
and removed almost allService::share_from_this()
calls from 'Service.cpp' the example above worked properly. So I thinkshared_from_raw()
is cause.
from rtt.
Excuse me, It seems I missed important information in original post: this issue is related with toolchain-2.9
version of OROCOS. Code in ~TaskContext is entirely different here.
from rtt.
Thanks for the detailed analysis!
- Method
clear()
in Service.cpp:219 is not recursive.removeService()
is called for each subservice, but it simply reset shared pointers and does not callclear() on corresponding Services. So if any of subservices has its own subservice we have
shared_ptr` loop.
You are right that this might be an issue in some scenarios, but making clear()
recursive might break existing use cases and is not a good option.
- Another possible cause is
shared_from_raw()
: Service.hpp:109. It seems there are many pitfalls related with this method: http://stackoverflow.com/questions/22184772/why-is-boostenable-shared-from-raw-so-undocumented
The article is right and relying on shared_from_raw()
is probably not the best design, but in this case I do not think it is an issue as the way services are used in Orocos the instances are always stored in a shared_ptr
immediately after construction.
I tried to replace
shared_ptr parent
byweak_ptr parent
inService.hpp
and it did not solve problem. But after I usedService * parent
and removed almost allService::share_from_this()
calls from 'Service.cpp' the example above worked properly. So I thinkshared_from_raw()
is cause.
Introducing weak_ptr
for the parent is a good option and along the lines of #193. There are also other use cases, like master/slave activity relationships (#178). On the other hand quite some code has to be checked against the case where getOwner()
or getParent()
might return null then also considering thread-safety. But that's still better than keep them around or have dangling raw pointers.
Excuse me, It seems I missed important information in original post: this issue is related with toolchain-2.9 version of OROCOS. Code in ~TaskContext is entirely different here.
You are right and the removal of the clear() call from ~TaskContext()
in 42a62e8#diff-a739de4d537602c73893d46c20da0a31L139 might be the issue. I will prepare a PR to re-add it and run some tests.
from rtt.
Introducing weak_ptr for the parent is a good option and along the lines of #193.
I tried it. For our project it worked fine. Service destructors are called in all cases: for global service subservice and for nested services of components. So from my viewpoint it solves the case.
Also I bumped in some issues with OCL (incorrect ROS messages decomposition in reporting components, inability to display service interface in rttlua console). If you want I can provide patches with fixes or walkarounds for them.
from rtt.
I merged #204 into the toolchain-2.9 branch. Feel free to open new issues or PRs for the other things you mentioned. Thanks!
from rtt.
Related Issues (20)
- no boost / RTTv3 HOT 1
- clarification on copyright HOT 3
- 2.9.1 ros debian package fails to install HOT 5
- Massive deadlocking when disconnecting connections in parallel HOT 2
- Portable install space HOT 10
- Omniorbpy
- rtt does not support const array ?
- orocos with imcompatiable gcc version (7.4) HOT 1
- cleanupHook called twice after in runtime -> exception -> cleanup
- sample given to setDataSample seem to sometimes "leak" to the other side HOT 3
- catkin build err HOT 2
- PluginLoader::loadTypekits throws boost::filesystem_error for "File name too long" with long path_list
- Problems installing OROCOS under Linux-RTAI/Xenomai HOT 4
- Value parse problem with user defined data in a property bag
- Windows build broken
- Could not allocate configuration semaphore 'sem' for ***,Throwing std::bad_alloc. HOT 1
- Orocos on raspberrypi 3b+ HOT 4
- How to properly configure services
- Communication between OROCOS components via Ethernet network HOT 3
- Deadlock when the input event port is disconnected from the output when the connection is active
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rtt.