Providing nil NSURLRequest to redirect completion handler hangs the NSURLSessionTask

Originator:nolan.d.obrien
Number:rdar://19860450 Date Originated:February 17th, 2015
Status:Open Resolved:
Product:iOS SDK Product Version:iOS 7+
Classification:Bug Reproducible:Always
 
Summary:
Per documentation, when the URLSession:task:willPerformHTTPRedirection:newRequest:completionHandler: callback is called, the completion handler is to be called with an unchanged newRequest (complete the redirect), a modified request (modify the redirect) or nil (cancel redirect and complete the task).

However, it is very common when nil is provided for the task to instead just go on until it times out and not actually cancel the redirect.

Enumeration of Repro:
iOS 7 + w/o Custom NSURLProtocol + https://google.com
No Repro
iOS 7 + w/o Custom NSURLProtocol + https://www.twitter.com
Repro
iOS 7 + Custom NSURLProtocol + https://google.com
Repro
iOS 7 + Custom NSURLProtocol + https://www.twitter.com
Repro
iOS 8 + w/o Custom NSURLProtocol + https://google.com
Repro
iOS 8 + w/o Custom NSURLProtocol + https://www.twitter.com
Repro
iOS 8 + Custom NSURLProtocol + https://google.com
Repro
iOS 8 + Custom NSURLProtocol + https://www.twitter.com
Repro

Steps to Reproduce:
1) set up an NSURLSession with defaults (in some cases, with any custom NSURLProtocol)
2) implement URLSession:task:willPerformHTTPRedirection:newRequest:completionHandler: so that it always calls the completionHandler with nil
3) run a request against https://google.com or https://www.twitter.com (two very common redirects)

Expected Results:
Redirect to cancel and task to complete

Actual Results:
Task doesn't complete and a timeout must be hit first (see "Enumeration of Repro" for further details)

Version:
iOS 7 or iOS 8

Configuration:
Simulator

Comments


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!