'Alamofire crash in session.swift deinit:
I am working on the Swift project and I have used the alamofire for handling the network. This crash only occurred in 14.6.0 and above the OS versions. I have attached the code below for creating/cancel session:
Session create:
func sessionManager() -> Session {
//SSL pining
instantiateTrustKit()
if let manage = self.manager {
return manage
}
else {
let configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForRequest = 30
self.manager = Session(configuration: configuration, delegate: CustomDelegate())
guard let sessionManager = manager else {
return Session.default
}
return sessionManager
}
}
Cancel ongoing request:
func cancelAllRequests() {
sessionManager().session.getTasksWithCompletionHandler { dataTasks, uploadTasks, downloadTasks in
dataTasks.forEach {
$0.cancel() }
uploadTasks.forEach {
$0.cancel() }
downloadTasks.forEach {
$0.cancel() }
}
}
Crash Stack trace:
Crashed: com.apple.root.background-qos
0 libobjc.A.dylib 0x25dd0 objc_release + 16
1 Alamofire 0xb4b90 Session.deinit + 204 (Session.swift:204)
2 Alamofire 0xb4c2c Session.__deallocating_deinit + 202 (Session.swift:202)
3 libswiftCore.dylib 0x383c98 _swift_release_dealloc + 40
4 libswiftCore.dylib 0x384b90 bool swift::HeapObjectSideTableEntry::decrementStrong<(swift::PerformDeinit)1>(unsigned int) + 288
- While sending requests we called the sessionManager function to get the current session.
- When the user opens the app for the first time and the user navigates to the main screen the cancel request function will be called.
Could anyone know the above issue?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
