Closed Ansis100 closed 1 week ago
I think I figured out what is causing this. I'm not entirely sure how to fix it because I am still not 100% familiar with the iOS codebase.
The processQueue
method calls item.enqueue()
on line 165. Before that it locks the state on line 153. Currently, any other methods that call lock()
will wait to be unlocked.
If the doEnqueue()
returns false (e.g. if the file cannot be found) then enqueue()
will attempt to clean up by calling taskFinished()
on line 231.
However, taskFinished()
ALSO has a lock()
on line 58, which prevents the method from ever executing because the call stack already contains a lock()
in processQueue()
.
As a result, the stateLock is forever locked and nothing can unlock it.
@781flyingdutchman does this look right to you? I removed the lock
call from taskFinished
as a temporary solution and it seemed to fix the forever-lock.
I had this frequently occur when trying to cancel a task on iOS and was just about to open an issue :)
Thanks for raising the issue and identifying the problem! Working on a fix
Implemented in 8.5.4
The app can enter a broken state where any
invokeMethod
call that uses theHoldingQueue
will cause the app to hang at thatawait
ed function call.I am not entirely sure how to reproduce the bug. My app mainly performs file uploads using background_downloader. It seems like the bug happens when work is being done by the uploader and the app loses its focus, e.g. is closed by the user or receives a phone call (based on my experience).
When the app is reopened, it locates the previous tasks in a custom DB to enqueue them again. When it tries to do so, it hangs on the
invokeMethod
call and gets stuck in this loop: https://github.com/781flyingdutchman/background_downloader/blob/21d5d2efc2a9c70e15214b08fb81826c2b156794/ios/Classes/HoldingQueue.swift#L241-L243Here is the
UploadTask
received by the uploader when the native code fails (copied from the debugger):From what I can see, it doesn't look that different from a normal task which enqueues successfully:
Is there any additional info I can provide to figure out what exactly might be causing this?