Very simple custom plugin fails with segmentation fault
Closed this issue · 3 comments
I am currently trying to create a custom reach plugin. However, even the most minimal plugin fails with a segmentation fault.
The segmentation fault happens at the fist call to the plugin. In my case it is an evaluator, therefore the first call to calculateScore
fails. Further debugging revealed that calls to calculateScore
still work as long as the factory object still exists, i.e. in the following code,
Lines 321 to 325 in 0d1d854
calculateScore
before line 325 works, after it, there is a segmentation fault.
Steps to reproduce and the corresponding source code can be found here: https://github.com/timonegk/reach_plugin_example
I've noticed this intermittently before as well. My understanding is that
- the plugin loader (
loader
) dynamically loads a library to createfactory
- I think this library should stay loaded in memory as long as
loader
is in scope
- I think this library should stay loaded in memory as long as
factory
uses the loaded library to produce an instance ofevaluator
that is independent offactory
- When
factory
goes out of scope, its library should still be loaded becauseloader
is still in scope. Similarly, the library forevaluator
should still be loaded becauseloader
is still in scope- In the case of the plugins in
reach
, they are in the same library as the rest of the core code, so that library probably can't be unloaded until the application is terminated; they may work mostly by coincidence. I don't think this is true for thereach_ros/2
plugins though
- In the case of the plugins in
There is a chance that when factory
goes out of scope, loader
unloads the library that provides the implementation of factory
. In your case, your factory and evaluator are defined in the same library. So if that library gets unloaded then that would explain why your evaluator segfaults.
Can you try separating your factory and evaluator into two different libraries as in the current reach
and reach_ros/2
repos and see if the issue persists?
The issue persists when separating factory and library (https://github.com/timonegk/reach_plugin_example/tree/f757465a70c446fc180ec06a1b59d3ec11ea2fb3) as well as when separating only the EXPORT_EVALUATOR_PLUGIN
macro (https://github.com/timonegk/reach_plugin_example/tree/d04cf96c6fafd654b8fafd6650d1037dff70c475).
Okay; thanks for checking on that.
Further debugging revealed that calls to calculateScore still work as long as the factory object still exists
If the problem is solved by making the factories persistent, I would be okay with merging that solution