7

I am calling a webservice from my iOS app which can take up to four minutes to return. I am using RestKit for the call and loading of the objects. What I'm finding is that when the requests are taking a long time, I get a Timeout error after ~60 seconds. I have tried setting the timeoutInterval to absurd amounts but it still times out after ~60.

RKObjectManager* objectManager = [RKObjectManager objectManagerWithBaseURL:HOSTNAME];

objectManager.client.requestQueue.showsNetworkActivityIndicatorWhenBusy = YES;
objectManager.client.disableCertificateValidation = YES;

//timeout
objectManager.client.timeoutInterval = 1000;

Here is the call to the service:

- (void)loadData 
{

NSString *uid = [self retrieveFromUserDefaults:@"login_preference"];
NSString *pwd = [self retrieveFromUserDefaults:@"password_preference"];

if([uid isEqualToString:@""] || [pwd isEqualToString:@""]){
    [self stopSpinner];
    [self enableUserInterface:YES];
    UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Missing Settings" 
                                                    message:@"Please enter your login information in the settings."
                                                   delegate:nil 
                                          cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    return;

}


RKObjectManager* objectManager = [RKObjectManager sharedManager];
NSDictionary *params = [NSDictionary dictionaryWithObjects: 
                        [NSArray arrayWithObjects:uid, pwd, nil] 
                                                   forKeys:[NSArray arrayWithObjects:@"uid", @"pwd", nil]]; 

// Load the object model via RestKit    
[objectManager loadObjectsAtResourcePath:[@"/synchData" appendQueryParams:params] delegate:self];

}

I'm doing the call to the webservice in a background thread - is there something in that design that could be causing the problem? I can't imagine what, like iOS not letting background threads run for longer than 60 seconds? I just can't figure out what is the problem.

Is the timeout the time it takes to get a response from the server, or to get the WHOLE response from the server? I am returning a potentially very large json response - do I need to return the whole thing within the timeout limit, or do I just need to get any response from the server within the limit?

Michaela
  • 493
  • 5
  • 19
  • Show us how you dispatch your requests. The timeout is the time your application waits until it gets any response, you don't need to return the whole thing within this time. – lawicko Jun 12 '12 at 13:32
  • Thanks - I added a bit, is that what you meant? I double checked and no matter what my timeout interval is, it's dying after 60 seconds. – Michaela Jun 12 '12 at 15:35
  • 1
    Yes, this is what I meant. I don't see anything wrong with your code, how do you catch the timeout? The RestKit docs say that the default timeout is set to 120 seconds and that timeout function `will return an RKRequestConnectionTimeoutError via didFailLoadWithError:`, so if you catch it in `requestDidTimeout:` there is a chance that some other mechanism invokes it. You may want to put a debugger in a method that catches the timeout and examine the call stack to find what exactly causes the timeout, perhaps this will help you to identify where the 60s value comes from. – lawicko Jun 12 '12 at 16:05
  • I catch it in didFailWithError. I never get to requestDidTimeout because that never gets called from RestKit since my RKRequestBackgroundPolicy is None. I guess I suck at debugging because when I get into my didFailWithError, I can't find anything in the stack to say what is causing it to die. – Michaela Jun 12 '12 at 17:26
  • Can you confirm you use the latest version? As per this [pull request](https://github.com/RestKit/RestKit/pull/491) this issue should be resolved already – mja Jun 12 '12 at 21:24
  • Yep, I have the latest. That _timeoutInterval added to RKClient is what I'm setting in my code, which was added in that commit. – Michaela Jun 13 '12 at 21:29
  • @Michaela Did you solve this issue? – Hamid Sep 16 '12 at 17:20
  • I have the same issue on Mac. 0.10.0 – Robert Kang Jun 02 '13 at 01:37
  • aha, this might help someone: https://github.com/RestKit/RestKit/issues/852 – Robert Kang Jun 02 '13 at 01:43

3 Answers3

2

If I understand your problem, the solution would be:

- (void)request:(RKRequest *)request didFailLoadWithError:(NSError *)error

So when you have problem with timeout interval, it will be caught at this method.

Joshua Dwire
  • 5,415
  • 5
  • 29
  • 50
Max Tymchii
  • 826
  • 8
  • 16
0

I am having a similar problem, the delegate method requestDidTimeout:(RKRequest*)request never being called. No matter if I set the timeout on RKRequest or RKClient.

Caveat: When setting the timeout on the request, I see the request NOT respecting the set timeout UNLESS I also call [requestObject createTimeOutTimer].

However, what I notice in your implementation is that you use 1000 for an NSTimeInterval: Do you mean 1000 seconds for the timeout? Change to 1 if you mean one second = 1000 msecs.

The default timeout on RestKit is 120 secs, so most likely this is an NSURLConnection timeout.

nine stones
  • 3,264
  • 1
  • 24
  • 36
0

For a long time Restkit library (version ~= .4) only supported adding timeoutInterval at a single place.

/**
An optional timeout interval within which the request should be cancelled.
This is passed along to RKRequest if set.  If it isn't set, it will default
to RKRequest's default timeoutInterval.
*Default*: Falls through to RKRequest's timeoutInterval
*/
@property (nonatomic, assign) NSTimeInterval timeoutInterval;

In RKResponseLoader.h

/**
The timeout interval, in seconds, to wait for a response to load.
The default value is 4 seconds.
@see [RKTestResponseLoader waitForResponse]
*/
@property (nonatomic, assign) NSTimeInterval timeout;
lal
  • 7,410
  • 7
  • 34
  • 45