781flyingdutchman / background_downloader

Flutter plugin for file downloads and uploads
Other
165 stars 76 forks source link

iOS upload task is kept idle(in running state) for long time until adding new task. #380

Closed bbalachandhar closed 1 month ago

bbalachandhar commented 2 months ago

Describe the bug

I am facing an issue with upload task in iOS, at the time of running state if we turn off the internet for few seconds and turn on then the task is not restarting. its kept in running state always until I add another new task in the queue to run.

I saw the changelog and similar issue was addressed in the version 8.5.4 so I updated my package version to 8.5.5 now and tried, but still I am facing the same issue.

Is there any workaround to fix this use case?

thanks, bala

781flyingdutchman commented 2 months ago

It's the OS that manages that pause and restart, so unfortunately not something that can be addressed directly. I don't know what algorithm they use to determine when to restart - the only thing I can think of is adding some timer around the upload/progress to "manually" cancel and reschedule the task.

781flyingdutchman commented 2 months ago

Also, have you tried to set higher priority on the task?

bbalachandhar commented 2 months ago

trying now with high priority flag

alopezetf commented 2 months ago

Hello @781flyingdutchman, I'm working with @bbalachandhar on this issue and after setting the Priority == 0 we did not see a the desired result related to the 'stalled' upload task. We did discover that if we submit a new and additional upload task (with no Internet interruption occurring) it will cause both upload tasks to complete as expected (including the 'stalled' task). Any additional thoughts? Thanks

781flyingdutchman commented 2 months ago

That's unfortunate. I don't have much further insight - iOS controls interrupted downloads and uploads at the OS level, different from Android which cancels the task when Internet is interrupted, allowing the downloader to manage retries. This is one area where iOS and Android behave differently, and since the downloader doesn't get to see the task until it generates an update or completes, it's hard to solve for. You could monitor internet connection state and start a timer when the Internet disappears, then when it re-appears you cancel the stalled task and reschedule it. It's a hack, but it may solve your problem on iOS.

alopezetf commented 1 month ago

Hello @781flyingdutchman - quick update... we are able to successfully cancel and reschedule a stalled task based on internet connectivity status, in similar fashion to your suggested workaround. Thanks