Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: Version 3.8.0 shuts down after searching for an entry. #3558

Merged
merged 3 commits into from
Dec 1, 2023

Conversation

MohitMaliFtechiz
Copy link
Collaborator

@MohitMaliFtechiz MohitMaliFtechiz commented Nov 28, 2023

Fixes #3556

Issue

The application was crashing when users rapidly typed to search for an entry. This was caused by frequent retrieval of search data from libkiwix, and the previous search job not being properly cleared, leading to it being retained in memory and causing crashes.

searchissue.mp4

Logs

Cmdline: org.kiwix.kiwixmobile
2023-11-28 17:14:15.098 19904-19904 DEBUG                   pid-19904                            A  pid: 19615, tid: 19747, name: DefaultDispatch  >>> org.kiwix.kiwixmobile <<<
2023-11-28 17:14:15.098 19904-19904 DEBUG                   pid-19904                            A        #00 pc 000000000042014c  /data/app/~~y5CudkmP7NaN7eUraxL42Q==/org.kiwix.kiwixmobile-j7pc34vRN3W8MRPBoXqAXQ==/base.apk!libkiwix.so (offset 0xe99000)
2023-11-28 17:14:15.098 19904-19904 DEBUG                   pid-19904                            A        #01 pc 0000000000420a04  /data/app/~~y5CudkmP7NaN7eUraxL42Q==/org.kiwix.kiwixmobile-j7pc34vRN3W8MRPBoXqAXQ==/base.apk!libkiwix.so (offset 0xe99000)
2023-11-28 17:14:15.098 19904-19904 DEBUG                   pid-19904                            A        #02 pc 0000000000422880  /data/app/~~y5CudkmP7NaN7eUraxL42Q==/org.kiwix.kiwixmobile-j7pc34vRN3W8MRPBoXqAXQ==/base.apk!libkiwix.so (offset 0xe99000)
2023-11-28 17:14:15.098 19904-19904 DEBUG                   pid-19904                            A        #03 pc 0000000000412b80  /data/app/~~y5CudkmP7NaN7eUraxL42Q==/org.kiwix.kiwixmobile-j7pc34vRN3W8MRPBoXqAXQ==/base.apk!libkiwix.so (offset 0xe99000)
2023-11-28 17:14:15.098 19904-19904 DEBUG                   pid-19904                            A        #04 pc 0000000000448bb0  /data/app/~~y5CudkmP7NaN7eUraxL42Q==/org.kiwix.kiwixmobile-j7pc34vRN3W8MRPBoXqAXQ==/base.apk!libkiwix.so (offset 0xe99000)
2023-11-28 17:14:15.098 19904-19904 DEBUG                   pid-19904                            A        #05 pc 00000000003f1cac  /data/app/~~y5CudkmP7NaN7eUraxL42Q==/org.kiwix.kiwixmobile-j7pc34vRN3W8MRPBoXqAXQ==/base.apk!libkiwix.so (offset 0xe99000)
2023-11-28 17:14:15.098 19904-19904 DEBUG                   pid-19904                            A        #06 pc 00000000003ef908  /data/app/~~y5CudkmP7NaN7eUraxL42Q==/org.kiwix.kiwixmobile-j7pc34vRN3W8MRPBoXqAXQ==/base.apk!libkiwix.so (offset 0xe99000) (Xapian::Query::Internal::postlist_sub_or_like(Xapian::Internal::OrContext&, QueryOptimiser*, double) const+28)
2023-11-28 17:14:15.098 19904-19904 DEBUG                   pid-19904                            A        #07 pc 00000000003f5778  /data/app/~~y5CudkmP7NaN7eUraxL42Q==/org.kiwix.kiwixmobile-j7pc34vRN3W8MRPBoXqAXQ==/base.apk!libkiwix.so (offset 0xe99000)
2023-11-28 17:14:15.098 19904-19904 DEBUG                   pid-19904                            A        #08 pc 00000000003f5778  /data/app/~~y5CudkmP7NaN7eUraxL42Q==/org.kiwix.kiwixmobile-j7pc34vRN3W8MRPBoXqAXQ==/base.apk!libkiwix.so (offset 0xe99000)
2023-11-28 17:14:15.098 19904-19904 DEBUG                   pid-19904                            A        #09 pc 00000000003f54fc  /data/app/~~y5CudkmP7NaN7eUraxL42Q==/org.kiwix.kiwixmobile-j7pc34vRN3W8MRPBoXqAXQ==/base.apk!libkiwix.so (offset 0xe99000)
2023-11-28 17:14:15.098 19904-19904 DEBUG                   pid-19904                            A        #10 pc 00000000004486b0  /data/app/~~y5CudkmP7NaN7eUraxL42Q==/org.kiwix.kiwixmobile-j7pc34vRN3W8MRPBoXqAXQ==/base.apk!libkiwix.so (offset 0xe99000)
2023-11-28 17:14:15.098 19904-19904 DEBUG                   pid-19904                            A        #11 pc 000000000044bc1c  /data/app/~~y5CudkmP7NaN7eUraxL42Q==/org.kiwix.kiwixmobile-j7pc34vRN3W8MRPBoXqAXQ==/base.apk!libkiwix.so (offset 0xe99000)
2023-11-28 17:14:15.098 19904-19904 DEBUG                   pid-19904                            A        #12 pc 00000000003e38c4  /data/app/~~y5CudkmP7NaN7eUraxL42Q==/org.kiwix.kiwixmobile-j7pc34vRN3W8MRPBoXqAXQ==/base.apk!libkiwix.so (offset 0xe99000) (Xapian::Enquire::Internal::get_mset(unsigned int, unsigned int, unsigned int, Xapian::RSet const*, Xapian::MatchDecider const*) const+504)
2023-11-28 17:14:15.098 19904-19904 DEBUG                   pid-19904                            A        #13 pc 000000000019215c  /data/app/~~y5CudkmP7NaN7eUraxL42Q==/org.kiwix.kiwixmobile-j7pc34vRN3W8MRPBoXqAXQ==/base.apk!libzim.so (offset 0x83e000) (zim::SuggestionSearch::getEstimatedMatches() const+92)
2023-11-28 17:14:15.098 19904-19904 DEBUG                   pid-19904                            A        #14 pc 0000000000027060  /data/app/~~y5CudkmP7NaN7eUraxL42Q==/org.kiwix.kiwixmobile-j7pc34vRN3W8MRPBoXqAXQ==/base.apk!libzim_wrapper.so (offset 0x80b000) (Java_org_kiwix_libzim_SuggestionSearch_getEstimatedMatches+124) (BuildId: 6c0d6ee977af86c7d817e067ec4176543043faa4)
2023-11-28 17:14:15.098 19904-19904 DEBUG                   pid-19904                            A        #20 pc 00000000000073b0  /data/data/org.kiwix.kiwixmobile/code_cache/.overlay/base.apk/classes11.dex (org.kiwix.kiwixmobile.core.search.viewmodel.SearchState.getVisibleResults+0)
2023-11-28 17:14:15.098 19904-19904 DEBUG                   pid-19904                            A        #25 pc 00000000000063a8  /data/data/org.kiwix.kiwixmobile/code_cache/.overlay/base.apk/classes10.dex (org.kiwix.kiwixmobile.core.search.SearchFragment$render$1$searchResult$1.invokeSuspend+0)
2023-11-28 17:14:15.098 19904-19904 DEBUG                   pid-19904                            A        #30 pc 000000000016f50c  [anon:dalvik-classes29.dex extracted in memory from /data/app/~~y5CudkmP7NaN7eUraxL42Q==/org.kiwix.kiwixmobile-j7pc34vRN3W8MRPBoXqAXQ==/base.apk!classes29.dex] (kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith+0)
2023-11-28 17:14:15.098 19904-19904 DEBUG                   pid-19904                            A        #35 pc 00000000001da870  [anon:dalvik-classes29.dex extracted in memory from /data/app/~~y5CudkmP7NaN7eUraxL42Q==/org.kiwix.kiwixmobile-j7pc34vRN3W8MRPBoXqAXQ==/base.apk!classes29.dex] (kotlinx.coroutines.DispatchedTask.run+0)
2023-11-28 17:14:15.098 19904-19904 DEBUG                   pid-19904                            A        #40 pc 00000000002359b8  [anon:dalvik-classes29.dex extracted in memory from /data/app/~~y5CudkmP7NaN7eUraxL42Q==/org.kiwix.kiwixmobile-j7pc34vRN3W8MRPBoXqAXQ==/base.apk!classes29.dex] (kotlinx.coroutines.internal.LimitedDispatcher.run+0)
2023-11-28 17:14:15.098 19904-19904 DEBUG                   pid-19904                            A        #45 pc 0000000000242d20  [anon:dalvik-classes29.dex extracted in memory from /data/app/~~y5CudkmP7NaN7eUraxL42Q==/org.kiwix.kiwixmobile-j7pc34vRN3W8MRPBoXqAXQ==/base.apk!classes29.dex] (kotlinx.coroutines.scheduling.TaskImpl.run+0)
2023-11-28 17:14:15.098 19904-19904 DEBUG                   pid-19904                            A        #50 pc 00000000002413a0  [anon:dalvik-classes29.dex extracted in memory from /data/app/~~y5CudkmP7NaN7eUraxL42Q==/org.kiwix.kiwixmobile-j7pc34vRN3W8MRPBoXqAXQ==/base.apk!classes29.dex] (kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely+0)
2023-11-28 17:14:15.098 19904-19904 DEBUG                   pid-19904                            A        #55 pc 000000000023f4b0  [anon:dalvik-classes29.dex extracted in memory from /data/app/~~y5CudkmP7NaN7eUraxL42Q==/org.kiwix.kiwixmobile-j7pc34vRN3W8MRPBoXqAXQ==/base.apk!classes29.dex] (kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask+0)
2023-11-28 17:14:15.098 19904-19904 DEBUG                   pid-19904                            A        #60 pc 000000000023f6ac  [anon:dalvik-classes29.dex extracted in memory from /data/app/~~y5CudkmP7NaN7eUraxL42Q==/org.kiwix.kiwixmobile-j7pc34vRN3W8MRPBoXqAXQ==/base.apk!classes29.dex] (kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker+0)
2023-11-28 17:14:15.098 19904-19904 DEBUG                   pid-19904                            A        #65 pc 000000000023f680  [anon:dalvik-classes29.dex extracted in memory from /data/app/~~y5CudkmP7NaN7eUraxL42Q==/org.kiwix.kiwixmobile-j7pc34vRN3W8MRPBoXqAXQ==/base.apk!classes29.dex] (kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run+0)

Fix

Implemented a debouncing mechanism to enhance the handling of search functionalities. This approach is employed to prevent unnecessary data loads from libkiwix, addressing the issue of crashes when users rapidly type and search for results.

searchissuefixed.mp4

Copy link

codecov bot commented Nov 28, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (acb9036) 48.99% compared to head (c90c631) 49.01%.

Additional details and impacted files
@@              Coverage Diff              @@
##             develop    #3558      +/-   ##
=============================================
+ Coverage      48.99%   49.01%   +0.02%     
- Complexity      1081     1083       +2     
=============================================
  Files            285      285              
  Lines          10448    10459      +11     
  Branches        1398     1398              
=============================================
+ Hits            5119     5127       +8     
- Misses          4501     4503       +2     
- Partials         828      829       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kelson42
Copy link
Collaborator

kelson42 commented Nov 28, 2023

@MohitMaliFtechiz If I understand properly, you can now only request suggestions in libkiwix once each 300ms. This is not how this kind of problem should be solved IMO. This will uselessly slowdown things on fast devices and if for any reason it takes more than 300ms, then app will crash.

You should:

  • Secure that two requests don’t run in parallel
  • Maybe this would be good that if someone is very quick typing we don’t send too many requests within a short amount of time.

BTW this pretty clearly a regression, so we had probabky a piece of code handling this. It shoukd be reintroduced, it might have been done appropriatly.

@gouri-panda
Copy link
Collaborator

@MohitMaliFtechiz @kelson42 is right. We should add debounce mechanisms with the help of coroutines flow here in the search. This will allow us to send one request at a given time, and the previous job will cancel. Also, we should add tests for this.

* Implemented a debouncing mechanism to enhance the handling of search functionalities. This approach is employed to prevent unnecessary data loads from libkiwix, addressing the issue of crashes when users rapidly type and search for results.
@MohitMaliFtechiz
Copy link
Collaborator Author

@kelson42, @gouri-panda I have added the debouncing mechanism for search functionality to avoid unnecessary data loading, to test this functionality I have added test cases properly.

@gouri-panda can you please re-review this PR.

@MohitMaliFtechiz MohitMaliFtechiz added this to the 3.8.1 milestone Nov 29, 2023
* Fixed: `Search action is debounced` test.
* Fixed: `SearchState combines sources from inputs` test.
Copy link
Collaborator

@gouri-panda gouri-panda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MohitMaliFtechiz Thanks 🎉

@kelson42 kelson42 merged commit c3e46bb into develop Dec 1, 2023
10 checks passed
@kelson42 kelson42 deleted the Issue#3556 branch December 1, 2023 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Version 3.8.0 shuts down after searching for an entry
3 participants