kiwix-android
kiwix-android copied to clipboard
Task/anr fix zimfile reader
Fixes #3929
This PR fixes the ANR thats being caused while trying to create the zimFileReader object. The UI was being blocked since we were creating the object on IO Thread but we are using runblocking which blocks the main thread. The solution to the problem was to suspend setZimFile and setZimFileDescriptor. Then tie the scope on lifecycleScope on the Fragments. When the zimFileReader is being created and it takes time for the initial load, the progressBar will be visible to the users and when Loading is complete, the progressBar will be Gone.
The solution doesn't block the Main Thread and instead switches the background work to a different thread(IO)
Screenshots
@MohitMaliFtechiz When I switch to different zimFiles, I get this crash after numerous attempts. I am not sure if its the same crash you were referring to earlier.
Cmdline: org.kiwix.kiwixmobile
2024-07-18 12:44:02.286 5611-5611 DEBUG pid-5611 A pid: 5387, tid: 5606, name: DefaultDispatch >>> org.kiwix.kiwixmobile <<<
2024-07-18 12:44:02.286 5611-5611 DEBUG pid-5611 A #00 pc 0000000000010630 /data/app/~~2cz1tgEo0aQgZshuQoQHsg==/org.kiwix.kiwixmobile-ZpQbVVYb8qkV5KrowJ_Pfg==/base.apk!libzim_wrapper.so (offset 0x1b2a000) (Java_org_kiwix_libzim_Archive_getEntryByPath__Ljava_lang_String_2+120) (BuildId: bb96395f5068f1755a93f5daa08b7a934333f07e)
2024-07-18 12:44:02.286 5611-5611 DEBUG pid-5611 A #02 pc 00000000020ad728 /memfd:jit-cache (deleted) (offset 0x2000000) (org.kiwix.kiwixmobile.core.reader.ZimFileReader.getItem+376)
2024-07-18 12:44:02.286 5611-5611 DEBUG pid-5611 A #03 pc 000000000214569c /memfd:jit-cache (deleted) (offset 0x2000000) (org.kiwix.kiwixmobile.core.reader.ZimFileReader.loadContent+204)
2024-07-18 12:44:02.286 5611-5611 DEBUG pid-5611 A #08 pc 0000000000008cd0 /data/data/org.kiwix.kiwixmobile/code_cache/.overlay/base.apk/classes13.dex (org.kiwix.kiwixmobile.core.reader.ZimFileReader.access$loadContent+0)
@CalebKL No it is not that crash i have uploaded the crash logs in the review comment.
Also, now on my device, it is crashing immediately when I switch to other zim files(I am using the old version of Android for testing Android 8).
Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 11992 (DefaultDispatch)
2024-07-18 16:33:50.291 12077-12077 DEBUG pid-12077 A pid: 11734, tid: 11992, name: DefaultDispatch >>> org.kiwix.kiwixmobile <<<
2024-07-18 16:33:50.294 12077-12077 DEBUG pid-12077 A #00 pc 0000000000010630 /data/app/org.kiwix.kiwixmobile-YaobaHgoDzW2aibsfWri3g==/base.apk (offset 0x71f000)
2024-07-18 16:33:50.294 12077-12077 DEBUG pid-12077 A #01 pc 000000000005be38 /data/app/org.kiwix.kiwixmobile-YaobaHgoDzW2aibsfWri3g==/oat/arm64/base.odex (offset 0x46000)
In the CoreReaderFragment there is a restore tabs functionality also for opening the previous zim file and restoring the previous tabs, and their article opens in the webView(if we are not opening the new zim file).
Currently, it is somehow restoring the previous zim file and tabs when we open the new file. However, it should not do it according to our openPageInBookFromNavigationArguments method's logic. Can you please check this? It is the main reason for these crashes.
@MohitMaliFtechiz When I switch to different zimFiles, I get this crash after numerous attempts.
This crash is newer, on which device you are testing.
@CalebKL No it is not that crash i have uploaded the crash logs in the review comment.
Also, now on my device, it is crashing immediately when I switch to other zim files(I am using the old version of Android for testing Android 8).
Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 11992 (DefaultDispatch) 2024-07-18 16:33:50.291 12077-12077 DEBUG pid-12077 A pid: 11734, tid: 11992, name: DefaultDispatch >>> org.kiwix.kiwixmobile <<< 2024-07-18 16:33:50.294 12077-12077 DEBUG pid-12077 A #00 pc 0000000000010630 /data/app/org.kiwix.kiwixmobile-YaobaHgoDzW2aibsfWri3g==/base.apk (offset 0x71f000) 2024-07-18 16:33:50.294 12077-12077 DEBUG pid-12077 A #01 pc 000000000005be38 /data/app/org.kiwix.kiwixmobile-YaobaHgoDzW2aibsfWri3g==/oat/arm64/base.odex (offset 0x46000)In the CoreReaderFragment there is a
restore tabsfunctionality also for opening the previous zim file and restoring the previous tabs, and their article opens in the webView(if we are not opening the new zim file).Currently, it is somehow restoring the previous zim file and tabs when we open the new file. However, it should not do it according to our
openPageInBookFromNavigationArgumentsmethod's logic. Can you please check this? It is the main reason for these crashes.
let me look into this as well
@MohitMaliFtechiz When I switch to different zimFiles, I get this crash after numerous attempts.
This crash is newer, on which device you are testing.
I got this crash while testing on my emulator, Pixel 7 pro API34 and also on Samsung S22+
@CalebKL Thanks, it is a native crash in libzim, but currently, our PR has many bugs and workarounds that can lead to this issue, so probably first we have to fix these things. @mgautierfr can have a better idea about this error when it occurs. Might be the data is corrupted at some point due to these scenarios.
Any news here?
Any news here?
There are some fixes that I am working on from @MohitMaliFtechiz reviews. I will complete it ASAP, although this PR will need to wait until the native error(3956) causing the crash is fixed.
@CalebKL I have found some serious issues in our implementation, especially when working with Coroutines(in a multithreading environment). With the main thread, there are no issues because the implementation was made according to the main thread. But now we are moving to use the Coroutines in our code. The issue we are facing in this PR is related to https://github.com/kiwix/kiwix-android/issues/4104 which I have already fixed in https://github.com/kiwix/kiwix-android/pull/4105.
In the meantime, we have also improved our code. So now, we have a better coroutine implementation to create an archive object on the IO thread. Also, we have improved the UI side to properly show users the progress when the archive object is in the creation process: https://github.com/kiwix/kiwix-android/pull/4074.
So now, you can start working on my review comments.
@MohitMaliFtechiz Can you please complete PR
@kelson42, @CalebKL has already started working on this issue. So let him complete this PR.
5 months without activity, this is too long by far, it should be completed.
5 months without activity, this is too long by far, it should be completed.
Completing this ASAP
@MohitMaliFtechiz Please complete PR
@CalebKL I have made the necessary changes, you can test and give your feedback.
@MohitMaliFtechiz Please rebase
Codecov Report
Attention: Patch coverage is 64.70588% with 12 lines in your changes missing coverage. Please review.
Project coverage is 56.73%. Comparing base (
948b8cc) to head (053b6e0). Report is 10 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #3937 +/- ##
============================================
+ Coverage 56.68% 56.73% +0.04%
- Complexity 1527 1532 +5
============================================
Files 313 313
Lines 13490 13510 +20
Branches 1693 1695 +2
============================================
+ Hits 7647 7665 +18
- Misses 4678 4681 +3
+ Partials 1165 1164 -1
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
@kelson42 Done.