*** Application termination due to the undetected exception "NSGenericException", reason: "The start date cannot be later than the end date!"

I use Alamofire, and after several hours of running my application on the simulator, I got a crash with this error.

*** Application termination due to the uncaught exception "NSGenericException", reason: "The start date cannot be later than the end date!"

I got a stack trace in the console:

*** First throw call stack: ( 0 CoreFoundation 0x0000000111186d4b __exceptionPreprocess + 171 1 libobjc.A.dylib 0x0000000110be821e objc_exception_throw + 48 2 Foundation 0x00000001107f0e3c -[_NSConcreteDateInterval dealloc] + 0 3 CFNetwork 0x00000001131a18e8 -[__NSCFURLSessionTaskMetrics _initWithTask:] + 868 4 CFNetwork 0x00000001131a1497 -[NSURLSessionTaskMetrics _initWithTask:] + 100 5 CFNetwork 0x0000000112f77bc7 -[__NSCFURLLocalSessionConnection _tick_finishing] + 351 6 libdispatch.dylib 0x00000001128e3978 _dispatch_call_block_and_release + 12 7 libdispatch.dylib 0x000000011290d0cd _dispatch_client_callout + 8 8 libdispatch.dylib 0x00000001128eae17 _dispatch_queue_serial_drain + 236 9 libdispatch.dylib 0x00000001128ebb4b _dispatch_queue_invoke + 1073 10 libdispatch.dylib 0x00000001128ee385 _dispatch_root_queue_drain + 720 11 libdispatch.dylib 0x00000001128ee059 _dispatch_worker_thread3 + 123 12 libsystem_pthread.dylib 0x0000000112cbc736 _pthread_wqthread + 1299 13 libsystem_pthread.dylib 0x0000000112cbc211 start_wqthread + 13 ) libc++abi.dylib: terminating with uncaught exception of type NSException 

Did someone get a similar crash?

thanks

+5
source share
4 answers

I had the same crash and did some research today and found this:

http://www.openradar.me/28301343

It looks like Apple fixed the problem in iOS 10.2. just thought it could help you!

+2
source

Yes, I have the exact same crash. This happened in the background thread, and it seems to be related to making a network request for a URL session. Interestingly, this is some kind of multithreaded error related to the fact that I make two network requests at the same time. I also use Alamofire, but I'm not sure if the error lies in Alamofire or in Apple code. At the moment, I could not reproduce it. Perhaps you can figure out how to reproduce it and then file an error message in the Apple kernel or in the Alamofire GitHub repository.

+2
source

This is an error in the Apple NSURLSessionTaskMetrics code and occurs during a network request, when the user clock moves backward enough so that the timestamp for the start of the request is after the request timestamp. This can be reproduced using a network debugging proxy and manual clock settings and only happens with iOS 10.0 to, but not including iOS 10.2

If you use Alamofire and you do not need NSURLSessionTaskMetrics , you can work around this by using the custom SessionDelegate for your SessionManager and overriding the responds(to aSelector..) function, for example:

 class MySessionDelegate: Alamofire.SessionDelegate { override public func responds(to aSelector: Selector) -> Bool { let result: Bool = super.responds(to: aSelector) if #available(iOS 10.2, *) { // NSURLSessionTaskMetrics date crash is fixed return result } else if #available(iOS 10.0, *) { // NSURLSessionTaskMetrics date crash is not fixed, turn off metric collection if aSelector == #selector(self.urlSession(_:task:didFinishCollecting:)) { return false } else { return result } } else { // NSURLSessionTaskMetrics doesn't exist return result } } } 

If you use the default SessionManager (for example, call Alamofire.request(...) ), you can create your own SessionManager to use your custom SessionDelegate :

 let sessionManager: Alamofire.SessionManager = { let configuration: URLSessionConfiguration = URLSessionConfiguration.default configuration.httpAdditionalHeaders = SessionManager.defaultHTTPHeaders return Alamofire.SessionManager(configuration: configuration, delegate: MySessionDelegate(), serverTrustPolicyManager: nil) }() 

And now, instead of calling Alamofire.request(...) you call sessionManager.request(...)

+1
source

I have been struggling with this issue in the os x app over the past few months and have found a workaround.

Background: Like OP am using Alamofire to request JSON data through a timer to send requests several times per second. The data comes as expected, but I get random crashes at irregular intervals with the same message as OP ie The start date cannot be later than the end date! etc.

Solution: Instead of sending Alamofire requests at regular intervals, I added some logic that checks for the return of the previous request before sending the next. This completely eliminated accidental crashes.

Hope this helps :)

 @thierryb 
0
source

Source: https://habr.com/ru/post/1260086/


All Articles