Deadlock in emscripten dynamic calls #2769
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Attempting to run an emscripten-built rust module lead me to a deadlock. I'm not quite sure what's wrong, but it looks to me like emscripten is calling itself through the host (No idea why. To catch exceptions?) and in the process, wasmer acquires a lock that is still held when calling back into the module. If the module tries that twice recursively, the simplest form of deadlock, a reentrancy deadlock is triggered.
The standard library doesn't have reentrant locks.
This cannot be solved by replacing the lock on
EmEnv.data
by an RwLock, because the code might also callsetTempRet0
, which does require a write lock.Maybe there is a way to get rid of the mutex entirely, but I do not see it.
The easy way out seems to be to clone the function (arcs), let go of the lock, and then do the call back into the module.
There are a few other instances of the same problematic pattern, but they call
memset
ormalloc
, which shouldn't call back into wasmer. I assume they are fine and left them alone, but have not done thorough testing.Review