apps-android-commons: Upload often fails or gets stuck, especially when uploading 3 or more pictures
Steps to reproduce:
- Take 3 (or more) interesting pictures of at least 2 MB (for instance pictures of cars or houses. If you need I can also provide many pictures, just send an email to the address found here).
- Get a slow Internet connection by installing the Throttly app and setting it to
Good 2G 450kbps↓ 150kbps↑. - In your gallery app, select the 3 (or more) pictures, tap
Share, then select the Commons app. - As soon as the upload starts, turn off your screen and do not touch your phone for 5 minutes.
- Some of the pictures will probably fail to upload.
Many other apps always upload reliably (for instance Gmail with attachments) even with slow Internet connections, even the Commons browser-based uploader seems to perform better, so hopefully we can fix this.
Possible strategy:
- Reproduce the issue with the Android Studio debugger (or similar), find out what the exact error message is.
- Based on the error message, change the app’s network parameters, such as timeout or buffer sizes.
- If still not reliable, implement a retry loop (for instance try again 3 times).
Measuring improvements:
- Percentage of failure with the reproduction steps above, as of 2023 January 12’s master branch:
- 1 failure out of a 3-pictures set upload on fast WiFi: 2 occurrences
- 2 failures out of a 10-pictures set upload on fast WiFi: 1 occurrence
- 6 failures out of a 9-pictures set upload on fast 5G: 1 occurrence
- 0 failures out of a 2-pictures set upload on slow WiFi: 1 occurrence
Some uploads get stuck (no progress despite the progress bar showing an animation). Among those stuck, some file have actually been uploaded already, some not.
Aggravating factors:
- Brief network disconnections, for instance when entering an elevator for 1 minute, seem to make uploads less reliable. I have not measured this theory but this could be investigated by putting your phone in a metal box (use a ping chart app to verify)
- I had many successes uploading from the custom picker, and many failures uploading by sharing from the gallery. There might be something about the app going to the background, or something other about activities, that might have an effect on reliability.
Recent Google Play comments:
- “Not a single photo is uploading even though i tried a dozen times”
- “50% of uploads are failed”
- “fails to upload pictures without saying the reason”
- “I can’t upload photos. They all say failed. Before it worked fine”
- “Photos cannot be uploaded”
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 15 (12 by maintainers)
Stashing is a way to first send the picture’s JPEG bytes to the server, then finalize the “upload” (file registration) a bit later.
This error occurs when the app sends the “Failed to Upload” notification.
The error is thrown at line 227 in UploadClient.java in the upload package
This happens when the condition uploadResult.getUpload() == null evaluates to true at line 223
Here uploadResult is of type UploadResponse
So uploadResult.getUpload() returns the nullable property upload of type UploadResult which is a data class
At line 221 in UploadClient.java the value of a gson.fromJson() call is stored in the uploadResult field
So uploadResult.getUpload() == null indicates that the upload property was returned as null by gson after parsing a JSON response from the server, which indicates that the server likely returned an empty or null response,
As uploadResult.getUpload() == null is true, an exception of type MwException is thrown.
The getErrorCode() method in MwException class returns error.getCode() where error is of type MwServiceError
A top-level comment in MwServiceError.java says “Gson POJO for a MediaWiki API error”
The class MwServiceError extends ServiceError which likely represents an error reported by the server via the API. It says “The API reported an error in the payload.”
All this happens when the uploadClient.uploadFileFromStash() method is called at line 296 in UploadWorker.kt
As the uploadClient.uploadFileFromStash() call causes an exception the onErrorReturn { } block is executed. A null value is passed here which causes the NullPointerException as shown in the Logcat screenshot attached first.
The exact error message is as below
The message Could not acquire locks on server rdb1 indicates that this is likely a problem with the server, rather than the Android client.
Two key methods are executed during the process in UploadWorker.kt:
while uploadFileToStash() turns out to be executed without a problem, uploadFileFromStash() causes the exception.
So what is Stash?
I’m still unsure what it is. But it is clear that it’s something the server handles. Refer https://www.mediawiki.org/wiki/Manual:UploadStash
I tried uploading multiple times and ended up with the exact same error.
@nicolas-raoul here are my findings about this issue. Discussing with the maintainers of Wikimedia Android Data Client and the API developers would be very helpful in solving this issue.
I just got upload stuck but uploading several medium-size sets (10 sets of 2 to 10 pictures).
On latest master, upload often gets stuck when uploading a set of around 10 pictures, this happened today on a very fast WiFi at home, not moving, but switching display off, on Pixel 6:
I can send the logcat if necessary.
@siva-subramaniam-v For me after step 2 upload is usually successful. If I understand correctly, multi-upload never works for you? If yes, would you mind creating a new GitHub issue? Thank you! 🙂