apache / apache/cordova-plugin-file-transfer
Timeouts after downloading a lot of files (iOS)
- Dominant language
- JavaScript
- Stars
- 606
- Forks
- 874
- PR merge metrics
- No merged PRs in 30d
Description
# Bug Report
## Problem
When you download a lot (more than 200) of files (images) consecutively, NSMutableURLRequest gets stuck after 50+ successful requests (and a few requests after that), because of the connection timeout.
You can see when it starts to happen, because few connections will get slower and slower until eventually it will time out.
Possibly this [link](https://stackoverflow.com/questions/13369386/how-to-cancel-a-persistent-connection-using-nsurlconnection) is related, idk.
As mentioned in the link above, [connection cancel] does nothing.
### What is expected to happen?
No timeouts.
### What does actually happen?
Timeouts.
Rewriting success call did not help but seem to improve a performance a little bit.
``` objective-c
// remove connection for activeTransfers
@synchronized (command.activeTransfers) {
[connection cancel];
[command.activeTransfers removeObjectForKey:objectId];
// remove background id task in case our upload was done in the background
[[UIApplication sharedApplication] endBackgroundTask:self.backgroundTaskID];
self.backgroundTaskID = UIBackgroundTaskInvalid;
[self.command.commandDelegate sendPluginResult:result callbackId:callbackId];
}
```
*Note that my JS code explicitly waits for ```[self.command.commandDelegate sendPluginResult:result callbackId:callbackId];``` before sending next request.
Contributor guide
Research direction
Start by reproducing the issue with more than 200 consecutive image downloads, then inspect the iOS code using NSMutableURLRequest, connection cancel, and activeTransfers. Check the request sequence around sendPluginResult and determine why connections slow and time out; done means sustained downloads complete without timeouts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, objective-c
- Domain
- mobile-dev, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100