NSURLSessionDownloadTask won't call its delegate methods if the hostname won't resolve

Originator:dloewenherz
Number:rdar://19419002 Date Originated:1/8/2015
Status:Behaves correctly Resolved:
Product:iOS SDK Product Version:8.1.2 (12B440)
Classification: Reproducible:Always
 
When creating an instance of NSURLSessionDownloadTask with a hostname that doesn't resolve, no NSURLSession delegate methods will get called (most notably, URLSession:task:didCompleteWithError will never get called). In most situations, this means that the app cannot know when the request did or did not complete without some hacky workarounds.

Steps to Reproduce:
1. Create an NSURLSession with a defined delegate, and define URLSession:task:didCompleteWithError on this delegate.
2. Create a NSURLSessionDownloadTask with a URL that doesn't resolve. I.e.,

NSURL *url = [NSURL URLWithString:@"http://testing1234442322.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLSessionDownloadTask *task = [mySession downloadTaskWithURL:url];
[task resume]

3. Run the app.

Expected Results:
URLSession:task:didCompleteWithError will get called.

Actual Results:
URLSession:task:didCompleteWithError never gets called, nor do any of the other delegate methods.

Comments

Update

Turns out that this is actually a documentation issue. See http://www.openradar.me/radar?id=6337324438781952

Apple's response:

This issue behaves as intended based on the following:

Assuming that this is for a background session configuration, then this behaves correctly. Background uploads / downloads will automatically wait for the server to become reachable (up until the timeoutIntervalForResource elapses).

Please update your bug report to let us know if this is still an issue for you.

By dloewenherz at Feb. 3, 2015, 11:44 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!