-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lifetime issues with mut.Morphology constructing sections with raw pointers to itself #161
Comments
The cut planes must be kept alive to prevent the morphology from being seeing its ref count fall to zero. BlueBrain/MorphIO#161
I have been thinking about this for a while. For me what seemed weird is that by design, a section is not supposed to be used after the morphology has been deleted. This is the analogue of attempting to use a node after you have deleted a graph. One proposal I have is to add a method '_raise_if_not_alive()' call at the beginning of each function so that it raises an actual error when the user attempts to do the manipulation you wrote. Would that be good? |
That's the simplified test case to aide in debugging. The issue is that one has to know this, and work around it (hence the 'Hack for morphio lifetime issue`.) Since python is a GC'd language, the expected behavior is that it should stay alive as long as you have a reference to it. Currently this is causing corruption that is silent, hard to track down, and can cause problems later. Ping @tomdele so he can be up to speed on this. |
To me this problem is kinda similar to this one I had in snap: I spent hours on this and could not find anything usable. The del from python is a much more complex beast than the c++ dtors (even if more handy). So this is not specific to MorphIO and easily reproducible in python only:
So what I can say is :
is probably a false assumption here. The corresponding |
The repro is kept as simple as possible, so that's why it uses The problem is that you can have references to sections that then disappear; for instance in the linked ticket: https://github.com/BlueBrain/NeuroR/pull/22/files/0c66835b70b4b543d804eb71f49875a44deaa0d4#diff-f2fc7ab6c036c0212f190055008dc918bf038637af88bef3d07a07e0d4d28ab8R294 The work-around being that one has to have |
We discussed this further with Benoit and I have a much better understanding of the whole issue. I think the del example was a bit misleading due to the python del behavior and the scoping from python. @wizmer brought up a solution using weak pointers instead of the raw pointers for the Section's morphology member. It results in a behavior that makes sense imao where : |
* when a mut::Morphology is deleted, and it resets the mut::Section::_morphology to null. * added getter to mut::Section to retrieve owning morphology that will throw if the above pointer is null * attempt to fix #161
* when a mut::Morphology is deleted, and it resets the mut::Section::_morphology to null. * added getter to mut::Section to retrieve owning morphology that will throw if the above pointer is null * attempt to fix #161: user should at least get an error if the lifetimes mismatch, which should help tracking errors down
Hello! |
The axons should be alive but you cannot use the topological functions on the sections like Basically, now you can do :
|
Exactly ! Wow, Tom is so good. |
I never doubted that! ;) I couldn't get back to that, but it seems we need to stick to current solution in the code, thanks! |
Yes, but the big difference is that now, if you try to get rid of the array that keeps the morphologies alive, you'll have a meaningful error message instead of a corrupted morphology. |
Lovely! |
Constructs like this:
Section(this, _counter, section_)
(wherethis
is mut::Morphology` - from)This means that a raw pointer is stored here that has a different lifetime than
Morphology
.This causes a use after free if the Morphology is dtor'd before the sections that have been created are removed, for example:
Note, this is different than #29
The text was updated successfully, but these errors were encountered: