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

Download failing immediately doesn't update UI #94

Open
Chralu opened this issue Mar 3, 2023 · 3 comments · May be fixed by #104
Open

Download failing immediately doesn't update UI #94

Chralu opened this issue Mar 3, 2023 · 3 comments · May be fixed by #104
Labels
bug Something isn't working ios Issue only affects or occurs most frequently on iOS

Comments

@Chralu
Copy link
Contributor

Chralu commented Mar 3, 2023

Describe the bug

When requesting a download that immediately fails, UI stays stucked on the "download in progress" state.

It might happen using iOS when episode URLs are non-SSL http://.
There might be other cases where download fails as soon as it starts.

To Reproduce

  1. Using iOS
  2. add the following podcast : https://feeds.feedburner.com/LaperoDuCaptain
  3. request any episode download.
  4. Episode in list keeps displayed as a download in progress. But download is actually stopped because OS refused http request.

Analyse

mobile_download_service.dart

  @override
  Future<bool> downloadEpisode(Episode episode) async {
 // ....
        final taskId = await downloadManager.enqueueTask(episode.contentUrl, downloadPath, filename);

        // Update the episode with download data
        episode.filepath = episodePath;
        episode.filename = filename;
        episode.downloadTaskId = taskId;
        episode.downloadState = DownloadState.downloading;
        episode.downloadPercentage = 0;

        await repository.saveEpisode(episode);
// ...
  }

Starting a download sequentially :

  1. Enqueues a download task in FlutterDownloader
  2. Gets the FlutterDownloader task id -> persists it in sembast Episode.downloadTaskId
  3. On download update, DownloadService
    1. looks for matching Episode.downloadTaskId in Sembast
    2. If episode is found, it is updated with new download progress.

In the case where download immediately fails, the download status changes before step 2. is done.
Then, a download update event arrives but DownloadService is unable to find the matching Episode in sembast.
=> Sembast episode is not updated
=> Repository.episodeListener is not updated
=> PodcastBloc is not updated

Screenshots

download_fail2.mp4

Smartphone (please complete the following information):

  • Device: iPhone11
  • OS: iOS 16
@Chralu
Copy link
Contributor Author

Chralu commented Mar 4, 2023

A solution would be to make step 2 synchronous. That way, we would be certain that Episode.downloadTaskId is changed on time.

I see two ways of implementing that :

  1. Replace Sembast by Isar which makes all read/write operations synchronous (by lazily doing actual persistence).
  2. Add a hand written memory cache on SembastRepository to make read/write operations synchronous (just like Isar does).

@amugofjava amugofjava added bug Something isn't working ios Issue only affects or occurs most frequently on iOS labels Mar 4, 2023
@amugofjava
Copy link
Owner

I will give this issue some thought. I have been thinking about db solutions as I feel that Anytime is starting to outgrow Sembast. Sembast is an excellent package and has made it very easy to incorporate a pure Dart data store solution, but its strengths are now starting to limit Anytime: I have to be very conscious of what data we store with Sembast being an in-memory store and with it not being cross isolate safe implementing background data fetching will be challenging. It may be that Sembast is replaced or complemented with another solution such as Isar, Objectbox or Realm. Replacing the entire DB layer is no small task.

@Chralu
Copy link
Contributor Author

Chralu commented Mar 5, 2023

I might be helpful on this kind of task.

a thought : Is null-safety migration prior to SGBD migration ?

Chralu added a commit to Chralu/anytime_podcast_player that referenced this issue Sep 15, 2023
Add a Lock to DownloadService. This ensures that download status updates are not processed while a download start/stop is requested (they are processed right after).
@Chralu Chralu linked a pull request Sep 15, 2023 that will close this issue
Chralu added a commit to Chralu/anytime_podcast_player that referenced this issue Sep 15, 2023
Add a Lock to DownloadService. This ensures that download status updates are not processed while a download start/stop is requested (they are processed right after).
Chralu added a commit to Chralu/anytime_podcast_player that referenced this issue Sep 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ios Issue only affects or occurs most frequently on iOS
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants