Closed oziade closed 9 years ago
Interesting, I haven't seen that before. You are calling a SwiftHTTP operation from a background thread? SwiftHTTP runs on its own background thread via an NSOperation subclass, so it is a background thread starting an NSOperation?
Sorry, i wanted to point that the error was in a background thread, but the operation is called (or added in NSOperationQueue) from the main thread. Most of the time, i just add the operation in the queue to cancel them if the screen is not displayed anymore (cancelAllOperations in deinit of ViewModel).
Ah ok makes sense. I started working on a swift-2 refactor and I noticed that the cancel
method might not be properly canceling/notifying as an NSOperation subclass should. I might try changing that method to:
override public func cancel() {
task.cancel()
finish()
}
and see if it fixes the random crashes. If it does, I will update both the branches to behave properly.
It sounds great. I finally could reproduce quite reliably the crash with the current version (with a completion field, where each character typed cancel all operations of the queue before adding a new operation). Then, I tried with your code above, and i could not reproduce the crash anymore. I did not remove the current call to super (do i have to remove it ??). So here is the code i tried :
override public func cancel() {
super.cancel()
task.cancel()
finish()
}
Thanks for the quick answer !
Sweet! Glad to hear that fixed, shocked it was wrong for so long (refactors can be good :smile: ). I pushed up a fix for both branches, thanks for the report!
I'm experimenting EXC_BAD_ACCESS crashes. This crash is not reproducible everytime, but happens sometimes for different users. I have the following crash log, which happens sometimes on some SwiftHTTP calls in background thread :
Did anyone experienced this ?