Fix deadlock between UriPermission and UriPermissionOwner
The deadlock happens when one thread, executing UriPermission#revokeModes, locks a UriPermission and then attempts to lock a UriPermissionOwner. Concurrently, another thread, executing UriPermissionOwner#removeUriPermission, locks the UriPermissionOwner and then attempts to lock the UriPermission. This is solved by creating the copy of the owner lists inside the synchronized block, but we perform the iteration and call removeReadPermission/removeWritePermission outside the block. 1) Because we iterate over a copy, the list we are looping through will not be modified by other threads. Hence b/371847603 is not re-introduced. 2) We are not holding the UriPermission lock when we call owner.removeReadPermission(). This breaks the circular lock dependency that was causing the deadlock. Memory implication should be small: 1) Shallow copy: Creates a new list but the actual object the list are the references and not the copies of original objects 2) Small number of owners: It's rare for a URI to be granted to more than a handful of applications at the same time. Therefore, the lists mReadOwners and mWriteOwners are usually not large. Bug: 400526943 Bug: 431868036 Bug: 432420249 Test: manual & pre-submit Flag: EXEMPT (bug fix) Change-Id: I8b39e883fd98e0ae847afc2e4c9d58945fc388f6
Loading
Please register or sign in to comment