2

I'm using ASIHTTPRequest to access my web service which is being hosted on Amazon EC2. It works great 98% of the time, but occasionally it just hangs up for awhile and eventually calls the didFail selector with the error message "A connection failure occurred". If I then resubmit the request right away it goes through fine. Any ideas what could be causing this behavior? While I like the library, if I can't solve this I may have to revert everything back to NSURLConnection, which I would rather not do.

I should note, all the URLs I am calling are https.

And here is the helper method I use to create all request objects:

-(ASIHTTPRequest*) createAPIRequest:(NSString*)_url post:(BOOL)_post {

    //encode the url
    NSURL *url = [NSURL URLWithString:_url];

    //create the right kind of request object
    ASIHTTPRequest *request;
    if (_post) {
        request = [ASIFormDataRequest requestWithURL:url];        
        [(ASIFormDataRequest*)request setPostValue:apiKey forKey:@"api_key"];
    } else {
        request = [ASIHTTPRequest requestWithURL:url];
    }

    //set the default values that all requests have
    [request setValidatesSecureCertificate:NO];
    [request setDelegate:self];
    [request setDidFinishSelector:@selector(requestDone:)];
    [request setDidFailSelector:@selector(requestWentWrong:)];
    [request setTimeOutSeconds:60];
    [request setShouldAttemptPersistentConnection:NO];

    return request;
}

I should also note, that there appears to be a similar question here. However, that issue appears to have been fixed in Sept 2011 and I am using v1.8.1-61 2011-09-19. I am also setting shouldAttemptPersistentConnection to NO just in case, and still getting the strange behavior.

EDIT: Here is the log from ASIHTTPRequest when it gets hung up.

2012-03-18 16:13:30:725 myApp[1735:74243] -[myAppAPI apiSetAlert:alertObject:] [Line 695] Attempting connection to http://api.t.myapp.com/1/devices/A4FA78A8-2BCB-49CD-BEE8-70ADA02156F9
2012-03-18 16:13:30:730 myApp[1735:105479] -[ASIFormDataRequest buildPostBody] [Line 211] 
==== Building an application/x-www-form-urlencoded body ====
api_key=123&a=123&b=1&c=31&d=1
==== End of application/x-www-form-urlencoded body ====

2012-03-18 16:13:30:733 myApp[1735:105479] -[ASIHTTPRequest startRequest] [Line 1374] [CONNECTION] Request <ASIFormDataRequest: 0x6993800> will not use a persistent connection
2012-03-18 16:13:31:488 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 46 bytes of bandwidth in last measurement period===
2012-03-18 16:13:32:738 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:33:988 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:35:238 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:36:488 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:37:737 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:38:987 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:40:237 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:41:487 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:42:737 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:43:987 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:45:237 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:46:487 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:47:737 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:48:986 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:50:237 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:51:487 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:52:737 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:53:987 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:55:236 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:56:487 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:57:736 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:58:986 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:00:238 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:01:487 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:02:737 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:03:986 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:05:236 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:06:485 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:07:735 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:08:986 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:10:235 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:11:485 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:12:736 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:13:985 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:15:235 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:16:485 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:17:735 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:18:985 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:20:235 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:21:485 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:22:736 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:23:985 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:25:234 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:26:484 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:27:735 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:28:987 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:30:235 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:31:484 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:32:734 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:35:234 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:36:484 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:37:734 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:38:983 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:40:234 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:41:484 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:42:734 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:43:984 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:45:233 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:46:478 myApp[1735:105479] -[ASIHTTPRequest failWithError:] [Line 2075] [STATUS] Request <ASIFormDataRequest: 0x6993800>: Failed
2012-03-18 16:14:46:480 myApp[1735:105479] -[ASIHTTPRequest failWithError:] [Line 2083] [CONNECTION] Request #(null) failed and will invalidate connection #(null)
2012-03-18 16:14:46:483 myApp[1735:74243] -[myAppAPI requestWentWrong:] [Line 79] requestWentWrong: 0 - A connection failure occurred
Community
  • 1
  • 1
Joel
  • 15,654
  • 5
  • 37
  • 60
  • I recommend editing `ASIHTTPRequestConfig.h` so that all debug output shows up, then look at it and update your question with any relevant extra info you can see. – Mike A. Mar 18 '12 at 22:28
  • I guess this will solve your issue. http://stackoverflow.com/questions/6082471/ios-development-why-do-i-always-get-the-a-connection-failure-occurred-on-the – Vaibhav Gautam Jun 28 '13 at 07:41

0 Answers0