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

[Backup] Bug fixes around backup cancellation and background #1173

Merged
merged 8 commits into from
Feb 20, 2024

Conversation

zatteo
Copy link
Contributor

@zatteo zatteo commented Feb 19, 2024

### 🐛 Bug Fixes

* Multiple bug fixes when backup is canceled by the user or when app goes to background

Checklist

Before merging this PR, the following things must have been done if relevant:

  • Tested on iOS
  • Tested on Android
  • Test coverage
  • README and documentation

We save the current upload id in a global variable to be able to
cancel an upload. On iOS, we saved it in the "begin" callback of
RNFS.uploadFiles function. We can save it sooner, before the start of the upload, so
before the "begin" callback, so let's do it to avoid having an not up
to date current upload id.
When the user was canceling a backup, we rejected with an error object
where detail property was "Upload canceled" and then we checked later
if the detail property was "User cancelled upload" to do stuff related
to cancellation. It was obviously not working.

Let's fix this by creating a CancellationError extending from Error
to never reproduce this kind of issue. CancellationError is also now
a standalone error and not a subset of upload errors.
No upstream PR has been made because package is inactive for 2 years.
Upload cancellation was not supported correctly on iOS.
When an upload was canceled, it was behaving like a NetworkError.
Thanks to the previous commit where we introduced a patch-package
to react-native-fs, we can handle the cancellation correctly.
…ckup" button

When the user try to stop the backup by clicking on the "Stop backup"
button, it was possible that a last media was uploaded. So the user
clicked "Stop button" with "10/100 medias uploaded" displayed, and it
stopped on "11/100 medias uploaded".

When we click on the "Stop backup" button, we :
- set a "shouldStop" boolean to true
- cancel the current upload if it exists and stop backup directly

The "shouldStop" boolean was only checked at the beginning of the
upload loop. The upload loop consists in :
1. "shouldStop" check
2. metadata + dedup stuff <-- if we stop upload during this phase, we
still do the upload and we stop upload at the next iteration
3. upload stuff

In this commit, we add a "shouldStop" check between 2. and 3.
Background backup is mostly unsupported. We were checking at the beginning
of the upload loop if we were in the background to stop the backup if
needed. This was highly inefficient because when going to background
the app could be freezed by the operating system before reaching
the next loop cycle. Now we listen to AppState changes to stop the
backup.

"stopBackup" can now be called with two reason leading to two error messages
sent to the user :
- stopped by the user
- stop because going to background
@zatteo zatteo force-pushed the fix/background-management-backup branch from 27fc6b3 to 0add571 Compare February 19, 2024 15:52
@zatteo zatteo merged commit 3cddf11 into master Feb 20, 2024
1 check passed
@zatteo zatteo deleted the fix/background-management-backup branch February 20, 2024 17:06
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.

2 participants