Skip to content

Conversation

@dconeybe
Copy link
Contributor

This is a port of cl/361876089:

JniRunnable: Fix a deadlock when Detach() is called from Run().

The deadlock occurred because Detach() attempted to acquire a write lock on a ReentrantReadWriteLock, which waits for all read locks to first be released; however, the Run() invocation on the call stack holds one of these read locks and therefore the read lock count will never reach zero causing the acquisition of the write lock to block forever.

This fix replaces the ReentrantReadWriteLock with standard Java synchronization. This implementation has the limitation that concurrent invocations of run() will be serialized with the advantage of a simple implementation. A more complicated version that allows concurrent invocations of run() is in a previous commit in this PR and is also recorded at https://gist.github.com/dconeybe/2d95fbc75f88de58a49804df5c55157b for potential future use.

@dconeybe dconeybe merged commit 12d5bea into main Mar 18, 2021
@dconeybe dconeybe deleted the dconeybe/PortChangelist361876089 branch March 18, 2021 13:39
dconeybe added a commit that referenced this pull request Mar 30, 2021
…lled from Run()

This changelist was previously ported in #330 but the integration testing component was lost in a merge.
@firebase firebase locked and limited conversation to collaborators Apr 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants