apigear-io / objectlink-core-cpp

A object link protocol for C++ 14
MIT License
0 stars 3 forks source link

Sink may be deleted but not removed from registry #19

Closed dorotaphanSiili closed 7 months ago

dorotaphanSiili commented 1 year ago

The library provides a registry which keeps ptrs to client node and a IObjectSink. The clientNode is our implementation and we can handle it properly - inform registry on dtor. But IObjectSink is just an interface which can be implemented anyhow by user In scenario: create registry create node create sink add to registry the sink with the node delete the sink - that does not inform registry about its death

, we don't force anywhere in olink library that sink has in its destructor the responsibility to remove itself from registry

From now on every use of sink from registry (e.g. clientNode would want to call olinkOnRelease(), or handle any message for it) we use deleted object. Options of fixing:

  1. Use weak_ptrs - this require the sink (also node) to have protected ctor, and factory method which returns the shared ptr to sink (node). When they are shared_ptrs then we can give weak ptrs to the registry. This way if it gets deleted we can always check before using if the object is alive
  2. Provide to client not ISinkObject interface but BaseSinkObject (and keep it in registry), which would get the registry in ctor, and always inform it on destruction. I can add an issue with that description and solution
dorotaphanSiili commented 7 months ago

Already solved. Registries keep weak_ptrs for nodes