Reputation: 20257
I am running into a really weird issue with NSURLConnection. I have a controller that makes three asynchronous GET requests in the viewDidLoad method using the following function:
+ (void)connectAsyncWithURL:(NSURL *)url httpMethod:(NSString *)httpMethod delegate:(id <NSURLConnectionDelegate>)delegate timeout:(NSTimeInterval)timeout
{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:timeout];
[request setHTTPMethod:httpMethod];
[NSURLConnection connectionWithRequest:request delegate:delegate];
}
The first two connections work as expected. The third however hangs until the timeout occurs. Doing a re-try after the failure causes the call to succeed. It doesn't seem to matter what order the requests are in - it's always the one that is called last that fails. I own the server the request is being made to, and watching the incoming network traffic shows me the first two requests, but the third does not appear for the third NSURLConnection until the initial timeout. What is even stranger is that after the timeout occurs, if I navigate away from the controller and back again, the issue is no longer reproducible until I restart the app.
Does anyone have any idea what could be causing this?
Upvotes: 0
Views: 90
Reputation: 5817
Some servers will limit the number of simultaneous connections from a single client to two. If this is the case, then the first two connections would succeed and the third would hang until one of the first two completes. Sounds like this would explain what you're seeing.
Upvotes: 3