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:
- Construct an NSURL with an http-based url pointing to a server that is currently offline.
- 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");
- Compare the timestamps of “begin” and “end”. though they should presumably differ by 5 seconds, they actually differ by exactly 30 seconds.
Any ideas?
Steve Mokris is a developer at Kosada, Inc.