iOS 11 URLSession doesn't recognise network disconnect when request in progress

Originator:vishnuprasath.g
Number:rdar://6468254623 Date Originated:11/9/2017
Status:Open Resolved:No
Product:iOS SDK Product Version:11.0
Classification:Bug Reproducible:Yes
 
Made a request in iOS 11 with URLSession and disconnected internet while request is in progress. Prior to iOS 11 URLSession dataTask request callback will throw an error immediately which gives information about failure reason with respective error object. But in iOS 11 after few minutes throws Time Out Error, instead it should work as like iOS 10.3 and below.
 
As suggested for iOS 11 I used waitsForConnectivity property as false in configuration. But it doesn't work either.
 
Xcode version: 9.0
Swift version: 3.0
iOS Version : iOS 11
macOS version running Xcode: 10.12.6
 
For more information visit https://forums.developer.apple.com/thread/89476 

Code which tried
 
func getResponse (_ urlString: String, completionHandler:@escaping CompletionHandlerBlock) {  
        let requestURL:String = getCompleteURL(urlString)  
       
        let configuration = URLSessionConfiguration.default  
        configuration.httpCookieStorage = nil  
        configuration.requestCachePolicy = NSURLRequest.CachePolicy.reloadIgnoringLocalAndRemoteCacheData  
        if #available(iOS 11.0, *) {  
            configuration.waitsForConnectivity = false  
        }  
        let session = URLSession(configuration: configuration)  
        var request = URLRequest(url: URL(string: requestURL)!)  
        request.httpMethod = "GET"  
        request.setValue("application/json", forHTTPHeaderField: "Content-Type")  
        
        let task = session.dataTask(with:request, completionHandler: {(data, response, error) -> Void in  
                print("Error",error)  
            if let data = data {  
                let json = try? JSONSerialization.jsonObject(with: data, options: [])  
                print("Response",json)  
                if let response = response as? HTTPURLResponse , 200...299 ~= response.statusCode {  
                } else {  
                }  
            }  
        })  
        task.resume()  
    }

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!