NSURLConnection's sendSynchronousRequest enforces minimum 30 second timeout?

While writing the new Image Downloader (Blocking) QC patch for CoreMelt, I ran into what appears to be a bug in Mac OS X’s NSURLConnection framework — if you construct an NSURLRequest and specify a timeout of less than 30 seconds, it’s ignored when you perform a [NSURLConnection sendSynchronousRequest:returningResponse:error:]. The request takes at least 30 seconds to time out, contrary to what the documentation suggests..

Steps to Reproduce:

  1. Construct an NSURL with an http-based url pointing to a server that is currently offline.
  2. Execute the following code block:
    NSLog(@"begin");
    NSURLRequest *request=[NSURLRequest
        requestWithURL:url
        cachePolicy:NSURLRequestReloadIgnoringCacheData
        timeoutInterval:5.0];
    NSData *data=[NSURLConnection
        sendSynchronousRequest:request
        returningResponse:&response
        error:&error];
    NSLog(@"end");
  3. Compare the timestamps of “begin” and “end”. though they should presumably differ by 5 seconds, they actually differ by exactly 30 seconds.

Any ideas?

On a somewhat related note, IOBluetooth inquiries have an application-configurable timeout that defaults to 10 seconds (the input is an unsigned char, so one would assume that it could inquire for up to 255 seconds). However, it appears to disregard this setting as well (on 10.5).

I am also facing the same issue. Previously when I was using iPhone SDK 2.1 my code was working fine but since when I have upgraded to 3.0 time out is not working its taking more than 30 secs. I my case I guess its 45 secs.

Let me know if you have come across any solution for this … or any alternative for the above functionality…

Thanks, Paresh Nawale

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <pre> <div> <span> <b> <i> <br> <table> <tr> <td> <th>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo].
  • You may insert videos with [video:URL]
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Adds typographic refinements.

More information about formatting options