-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Stuck downloads when changing network conditions #6798
Comments
This is probably a duplicate of #6733. Marking as such, but please do test with the |
@ojw28 Unfortunately this issue still exists on the latest dev-v2 branch (Tested on 826083d). The below patch fixes the issue and I'll put together a better change and submit a pr later. Any chance you could reopen this issue please?
|
Thanks for checking! I see what's going on now, and yes you're absolutely right. What's happening in this case is that the Your PR will cause the |
As discovered whilst investigating #6798, there are cases where these methods are not correctly. They were added as convenience methods that could be overridden by concrete DownloadService implementations, but since they don't work properly it's preferable to require application code to listen to their DownloadManager directly instead. Notes: - The original proposal to fix #6798 stored the state change events in memory until they could be delivered. This approach is not ideal because the events still end up being delivered later than they should be. We also want to fix the root cause in a different way that does not require doing this. - This change does not fix #6798. It's a preparatory step. Issue: #6798 PiperOrigin-RevId: 289418555
Issue: #6798 PiperOrigin-RevId: 289424582
- DownloadManagerHelper now passes all downloads to the DownloadService when the service is attached (and once the downloads are known). The service then starts the foreground notification updater if necessary. This fixes the ref'd issue. - Don't call getScheduler() if the service is background only. This was already documented to be the case on the DownloadService constructor. - If the service is started in the foreground on SDK level 26 and higher, satisfy the condition to move the service to the foreground in onStartCommand rather than in stop(). It's much more obviously correct, and should produce the same end result. Issue: #6798 PiperOrigin-RevId: 290050024
This should be fixed in Note that there's still some additional work to be done, which should speed up resumption in the case that the process is still in memory (and also fix this case if |
This fixes an issue where a DownloadService implementation that allows foreground but doesn't provide a scheduler would not be restarted in the case that it was still in memory but classed as idle by the platform. It also speeds up service restart in the case that a scheduler is provided. Issue: #6798 PiperOrigin-RevId: 290068960
- Add additional Listener methods to DownloadManager, to inform of changes to whether the downloads are paused or waiting for requirements. - Only schedule the Scheduler if we really are waiting for requirements. - Only restart the service if we're no longer waiting for requirements, and if there are queued downloads that will now be restarted. Previously the service would be restarted whenever the requirements were met, regardless of whether there was any work to do. - Restart service if it might be stopping, as well as if it's already stopped. Also restart service if there's a download state change to a state for which the service should be started, if. Issue: #6798 PiperOrigin-RevId: 290270547
As discovered whilst investigating #6798, there are cases where these methods are not correctly. They were added as convenience methods that could be overridden by concrete DownloadService implementations, but since they don't work properly it's preferable to require application code to listen to their DownloadManager directly instead. Notes: - The original proposal to fix #6798 stored the state change events in memory until they could be delivered. This approach is not ideal because the events still end up being delivered later than they should be. We also want to fix the root cause in a different way that does not require doing this. - This change does not fix #6798. It's a preparatory step. Issue: #6798 PiperOrigin-RevId: 289418555
Issue: #6798 PiperOrigin-RevId: 289424582
- DownloadManagerHelper now passes all downloads to the DownloadService when the service is attached (and once the downloads are known). The service then starts the foreground notification updater if necessary. This fixes the ref'd issue. - Don't call getScheduler() if the service is background only. This was already documented to be the case on the DownloadService constructor. - If the service is started in the foreground on SDK level 26 and higher, satisfy the condition to move the service to the foreground in onStartCommand rather than in stop(). It's much more obviously correct, and should produce the same end result. Issue: #6798 PiperOrigin-RevId: 290050024
This fixes an issue where a DownloadService implementation that allows foreground but doesn't provide a scheduler would not be restarted in the case that it was still in memory but classed as idle by the platform. It also speeds up service restart in the case that a scheduler is provided. Issue: #6798 PiperOrigin-RevId: 290068960
- Add additional Listener methods to DownloadManager, to inform of changes to whether the downloads are paused or waiting for requirements. - Only schedule the Scheduler if we really are waiting for requirements. - Only restart the service if we're no longer waiting for requirements, and if there are queued downloads that will now be restarted. Previously the service would be restarted whenever the requirements were met, regardless of whether there was any work to do. - Restart service if it might be stopping, as well as if it's already stopped. Also restart service if there's a download state change to a state for which the service should be started, if. Issue: #6798 PiperOrigin-RevId: 290270547
Cleanup is complete, and the changes are in |
How many times do you generally have to try for it to reproduce? I haven't managed to reproduce the problem yet (using the same version you were using). |
A couple of additional:
|
We do now have reproduction steps for one case in which downloads fail to resume when network connectivity is restored. We're tracking this using #7453. |
Issue description
DownloadService race condition causing downloads to not resume when network requirements are met after previously not being met.
The issue appears to be that
DownloadManagerHelper.onDownloadChanged
is called before the new service is attached to theDownloadManagerHelper
. ThereforeDownloadService.notifyDownloadChanged
is never called andstartForeground
is never called on the new service. The app process is then killed after roughly 10 seconds as the scheduler has been cancelled.Reproduction steps
Using the exoplayer app:
Link to test content
Tested using
WV: Clear SD & HD (MP4,H264)
in the sample app.Version of ExoPlayer being used
2.10.7. Also reproduced the issue on 2.11.1.
Device(s) and version(s) of Android being used
Pixel 3XL Android 10 (QQ1A.191205.008)
The text was updated successfully, but these errors were encountered: