File loading race condition leads to crashes
[Update 2022-05-25: added more details to clarify the race]
- A file loading operation calls the plugins's
load()
function called in a new thread -
load()
usesaddEmptyObject()
is used to create an object to hold the loaded file. - This emits the
emptyObjectAdded
signal, which is connected toCore::slotEmptyObjectAdded
-
Core::slotEmptyObjectAdded
emitssignalObjectUpdated(_id)
andsignalObjectUpdated(_id, UPDATE_ALL)
Now these two things can happen in parallel:
- In the loading thread, file loading (e.g. OM or OVM) occurs
- Other plugins get notified vis
slotObjectUpdated
and can operate on this unfinished object at the same time
In particular, PropertyVisPlugin::slotObjectUpdated
does cause crashes for me, but likely is not the only problematic plugin.
With OM, this can lead to a crash while properties are loaded from the file with the following order of execution:
- Main thread, propvis'
OMPropertyModel<...>::gatherProperties()
callsmesh_->fprops_begin()
- File load thread:
OpenMesh::PropertyCreator::create_property()
, this invalidates the fprops_begin iterator - Main thread: The Property iterator is dereferenced -> crash
I attached the output of an ASAN instrumented build that runs into this with detailed backtraces:
of-load-om-race-condition-asan-output.txt
How should we go about solving this? Maybe just putting a mutex around mesh access from objects? This would also prevent similar issues when performing mesh processing in a worker thread.