Avoid ANRs in dumpCacheInfo
Bug: 233566891 PropertyInvalidatedCache.dumpCacheInfo() sometimes triggers an ANR in system_server, with a thread blocked writing to dumpsys TransferPipe while holding a cache lock. Other threads are blocked on the cache lock. There does not seem be a true deadlock, but if IO is slow then all the threads slow down enough to trigger the ANR. This change stages the output of dumpCacheInfo() in a byte array. The byte array is written while holding the appropriate cache locks. When the byte array has been completely generated and all locks have been released, the output is sent back to the caller over the dumpsys TransferPipe. The two PrintWriter objects are properly closed now. The previous code worked as a side effect of the many calls to flush(), which are unnecessary now. As a consequence of this change, it will be possible add a unit-test for the output of 'dumpsys cacheinfo' by calling the method that creates the byte array. Such a unit test is not part of this commit.cache. Tested manually by running 'dumpsys cacheinfo' and verifying that the output is correct. Test: * FrameworksCoreTests:IpcDataCacheTest Change-Id: Icbd0197ca883cf0560ba2eb637951abee033eced
Loading
Please register or sign in to comment