You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[HOLD for payment 2023-08-10] [$1000] Android - User is able to click on download button on share code page after modal shows up if user is clicks rapidly and app crashes #23094
Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.ExternalAdded to denote the issue can be worked on by a contributorReviewingHas a PR in reviewWeeklyKSv2
Click on the download button rapidly multiple times
Do step 3 until app crashes
Expected Result:
User should not be able to click on the download button more than once then the confirmation modal should show up. App should not crash if user clicks on download button multiple of times
Actual Result:
User is able to click on the download button more than once even after the confirmation modal shows up if user is clicking on the download button rapidly multiple of times. And if user continues to do this for a few seconds app crashes.
Workaround:
Unknown
Platforms:
Which of our officially supported platforms is this issue occurring on?
Android / native
Android / Chrome
iOS / native
iOS / Safari
MacOS / Chrome / Safari
MacOS / Desktop
Version Number: 1.3.41-3 Reproducible in staging?: y Reproducible in production?: y If this was caught during regression testing, add the test name, ID and link from TestRail: Email or phone of affected tester (no customers): Logs:https://stackoverflow.com/c/expensify/questions/4856 Notes/Photos/Videos: Any additional supporting documentation
Please re-state the problem that we are trying to solve in this issue.
Android - User is able to click on download button on share code page after modal shows up if user is clicks rapidly and app crashes
What is the root cause of that problem?
When user tried to press many times into download button, Android app will be crashed, since our handleDownload tried to create 2 file with the same name which caused this issue.
What changes do you think we should make in order to solve the problem?
We can simply wrap our download function with debounce to avoid this issue happened again.
this.downLoadQrCode=_.debounce(this.downLoadQrCode.bind(this),500);downLoadQrCode(){this.qrCodeRef.current?.download()}// then use it{isNative&&(<MenuItemisAnonymousActiontitle={this.props.translate('common.download')}icon={Expensicons.Download}// eslint-disable-next-line es/no-optional-chainingonPress={this.downLoadQrCode}/>
What alternative solutions did you explore? (Optional)
Use Download.setDownload similar the way we used to download attachment, we only enable Download button again after attachment is downloaded.
First, we need to understand why the crash/error happens. Here is the error message of the crash:
Based on the stack trace above, the error comes from copyToMediaStore->createNewMediaFile->resolver.insert here:
Notice that the logic is only for Android 10 (Q) and above.
I don't find an official documentation stating why the error occurs, but I found a comment mentioning that this error happens when we save the same file name > 30 files. On my Android device, the error starts to happen when saving the 33rd image.
So, it's not about quickly pressing the download. We can even reproduce this issue by downloading the same report attachment and 2FA codes > 30 times.
Here is the video showing the error on the report attachment.
WhatsApp.Video.2023-07-19.at.21.37.17.mp4
What changes do you think we should make in order to solve the problem?
To allow users to keep downloading the same attachment over and over, we have 2 options:
Always append the attachment name with the current time. This way we won't have a file with the same name. (similar to WhatsApp)
OR
Only append the attachment name after we get an error (similar to Chrome, see image below), but we currently unable to do this
We actually already have a catch block to catch any error here:
+try {
// Keeps a handle to the new file's URI in case we need to modify it later.
return resolver.insert(mediauri, fileDetails);
+} catch (Exception ex) { return null }
changed the title [-]Android - User is able to click on download button on share code page after modal shows up if user is clicks rapidly and app crashes[/-][+][$1000] Android - User is able to click on download button on share code page after modal shows up if user is clicks rapidly and app crashes[/+]on Jul 20, 2023
I think @kidroca is fixing it along with the PR, do we want to create a separate PR for the fix? (Btw, I don't know how to receive an image from Concierge)
Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.ExternalAdded to denote the issue can be worked on by a contributorReviewingHas a PR in reviewWeeklyKSv2
Activity
melvin-bot commentedon Jul 18, 2023
Triggered auto assignment to @twisterdotcom (
Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.melvin-bot commentedon Jul 18, 2023
Bug0 Triage Checklist (Main S/O)
Platformsin OP are ✅)hungvu193 commentedon Jul 18, 2023
Proposal
Please re-state the problem that we are trying to solve in this issue.
Android - User is able to click on download button on share code page after modal shows up if user is clicks rapidly and app crashes
What is the root cause of that problem?
When user tried to press many times into download button, Android app will be crashed, since our

handleDownloadtried to create 2 file with the same name which caused this issue.What changes do you think we should make in order to solve the problem?
We can simply wrap our download function with debounce to avoid this issue happened again.
What alternative solutions did you explore? (Optional)
Use
Download.setDownloadsimilar the way we used to download attachment, we only enable Download button again after attachment is downloaded.bernhardoj commentedon Jul 19, 2023
Proposal
Please re-state the problem that we are trying to solve in this issue.
Downloading the Share code multiple times will crash the app on Android, starting on Android 10.
What is the root cause of that problem?
The download button will call
fileDownloadfunction. Here are the steps of how a file is downloaded on Android:handleDownloadApp/src/libs/fileDownload/index.android.js
Lines 103 to 108 in 16a83ac
App/src/libs/fileDownload/index.android.js
Lines 51 to 62 in 16a83ac
App/src/libs/fileDownload/index.android.js
Lines 65 to 82 in 16a83ac
The error happens on the 3rd step.
First, we need to understand why the crash/error happens. Here is the error message of the crash:

Based on the stack trace above, the error comes from

copyToMediaStore->createNewMediaFile->resolver.inserthere:Notice that the logic is only for Android 10 (Q) and above.
I don't find an official documentation stating why the error occurs, but I found a comment mentioning that this error happens when we save the same file name > 30 files. On my Android device, the error starts to happen when saving the 33rd image.
So, it's not about quickly pressing the download. We can even reproduce this issue by downloading the same report attachment and 2FA codes > 30 times.
Here is the video showing the error on the report attachment.
WhatsApp.Video.2023-07-19.at.21.37.17.mp4
What changes do you think we should make in order to solve the problem?
To allow users to keep downloading the same attachment over and over, we have 2 options:
OR
We actually already have a
catchblock to catch any error here:App/src/libs/fileDownload/index.android.js
Lines 73 to 89 in 16a83ac
The problem is, the library that we use, which is
react-native-blob-utildoesn't catch the native error, so we have no way to catch the error on the JS side. The solution is to raise a PR upstream to catch the error natively.https://github.com/RonRadtke/react-native-blob-util/blob/48735c72ff8f442db215aff1bef68c53bc3c5582/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilMediaCollection.java#L98-L99
By returning null on error, it will get rejected here:
https://github.com/RonRadtke/react-native-blob-util/blob/48735c72ff8f442db215aff1bef68c53bc3c5582/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilImpl.java#L422-L425
After we did the above fix, we can now catch the error and retry the file copying with a different file name that is appended with the current time:
twisterdotcom commentedon Jul 20, 2023
Okay nice. This is a nice legit bug.
[-]Android - User is able to click on download button on share code page after modal shows up if user is clicks rapidly and app crashes[/-][+][$1000] Android - User is able to click on download button on share code page after modal shows up if user is clicks rapidly and app crashes[/+]melvin-bot commentedon Jul 20, 2023
Job added to Upwork: https://www.upwork.com/jobs/~01ea9db9c8634d571d
melvin-bot commentedon Jul 20, 2023
Current assignee @twisterdotcom is eligible for the External assigner, not assigning anyone new.
melvin-bot commentedon Jul 20, 2023
Triggered auto assignment to Contributor-plus team member for initial proposal review - @parasharrajat (
External)32 remaining items
parasharrajat commentedon Aug 9, 2023
Payment requested with bonus. Ref: #23094 (comment)
twisterdotcom commentedon Aug 9, 2023
Payment summary:
@parasharrajat will be paid via newDot $1500
@bernhardoj will be paid via Upwork $1500: https://www.upwork.com/nx/wm/offer/26030844
@Nathan-Mulugeta will be paid via Upwork $250: https://www.upwork.com/nx/wm/workroom/34308785/overview
twisterdotcom commentedon Aug 10, 2023
All paid.
JmillsExpensify commentedon Aug 16, 2023
Review the details for @parasharrajat. Approved for payment in NewDot based on the BZ summary above.
kidroca commentedon Aug 21, 2023
Hey team,
I've identified a bug that appears to be a regression linked to the changes introduced in the current ticket.
jasperhuangg commentedon Aug 21, 2023
@kidroca Thanks! Normally we leave regressions for the person who implemented the solution to fix. @bernhardoj Please fix the regression!
bernhardoj commentedon Aug 21, 2023
I think @kidroca is fixing it along with the PR, do we want to create a separate PR for the fix? (Btw, I don't know how to receive an image from Concierge)