Crash I cannot resolve since a long time - ios

This is what appear in crash log for crashlytics:
Crashed: com.apple.main-thread
0 FieldService 0x665cc specialized MonthNameFormater.stringForValue(_:axis:) + 4304774604 (GraphViewController.swift:4304774604)
1 FieldService 0x5fd74 #objc MonthNameFormater.stringForValue(_:axis:) + 4304747892 (:4304747892)
2 Charts 0xcc4c AxisBase.getFormattedLabel(_:) + 149 (AxisBase.swift:149)
3 Charts 0xcaa8 AxisBase.getLongestLabel() + 138 (AxisBase.swift:138)
4 Charts 0xb0c78 XAxisRenderer.computeSize() + 158 (XAxisRenderer.swift:158)
5 Charts 0xb0b3c XAxisRenderer.computeAxisValues(min:max:) + 154 (XAxisRenderer.swift:154)
6 Charts 0x1cb9c BarLineChartViewBase.notifyDataSetChanged() + 592 (:592)
7 Charts 0x57ee8 ChartViewBase.data.didset + 656 (:656)
8 Charts 0x54750 ChartViewBase.data.setter + 84 (:84)
9 FieldService 0x62368 GraphViewController.updateGraph() + 4304757608 (:4304757608)
10 FieldService 0x610e0 closure #1 in closure #1 in GraphViewController.viewDidLoad() + 4304752864
11 FieldService 0xb2000 thunk for #escaping #callee_guaranteed () -> () + 4305084416 (:4305084416)
12 libdispatch.dylib 0x1e6c _dispatch_call_block_and_release + 32
13 libdispatch.dylib 0x3a30 _dispatch_client_callout + 20
14 libdispatch.dylib 0x11f48 _dispatch_main_queue_drain + 928
15 libdispatch.dylib 0x11b98 _dispatch_main_queue_callback_4CF + 44
16 CoreFoundation 0x51800 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
17 CoreFoundation 0xb704 __CFRunLoopRun + 2532
18 CoreFoundation 0x1ebc8 CFRunLoopRunSpecific + 600
19 GraphicsServices 0x1374 GSEventRunModal + 164
20 UIKitCore 0x514b58 -[UIApplication _run] + 1100
21 UIKitCore 0x296098 UIApplicationMain + 364
22 FieldService 0x6b74 main + 20 (AppDelegate.swift:20)
23 ??? 0x1018a9da4 (Missing)
As you can see, a lot of users is impacted with it.
And this is my class called MonthNameFormatter. What and where is the issue?
import Charts
import CoreData
class MonthNameFormater: IndexAxisValueFormatter {
override func stringForValue(_ value: Double, axis: AxisBase?) -> String {
let symbols = Calendar.localizedCurrent.shortMonthSymbols
let index = min(Options.shared.isTheocraticYearEnabled ? (Int(value) + 8) % 12 : Int(value), 11)
guard symbols.count == 12 else {
return "-"
}
return symbols[index]
}
}
Where do I use it in code?
private let chartView: LineChartView = {
let view = LineChartView()
view.xAxis.labelPosition = .bottom
view.rightAxis.enabled = false
view.borderLineWidth = 0
view.xAxis.valueFormatter = MonthNameFormater()
view.xAxis.granularity = 1
view.isUserInteractionEnabled = false
return view
}()
This is an info from Xcode
Thread 0 name:
Thread 0 Crashed:
0 FieldService 0x0000000104f665cc Swift runtime failure: Index out of range + 0 (:0)
1 FieldService 0x0000000104f665cc specialized _ArrayBuffer._checkInoutAndNativeTypeCheckedBounds(_:wasNativeTypeChecked:) + 0 (:0)
2 FieldService 0x0000000104f665cc specialized Array._checkSubscript(_:wasNativeTypeChecked:) + 0 (GraphViewController.swift:0)
3 FieldService 0x0000000104f665cc specialized Array.subscript.getter + 0 (GraphViewController.swift:17)
4 FieldService 0x0000000104f665cc specialized MonthNameFormater.stringForValue(_:axis:) + 744
5 FieldService 0x0000000104f66498 specialized MonthNameFormater.stringForValue(_:axis:) + 436 (:0)
6 FieldService 0x0000000104f5fd74 MonthNameFormater.stringForValue(_:axis:) + 4 (:0)
7 FieldService 0x0000000104f5fd74 #objc MonthNameFormater.stringForValue(_:axis:) + 16
8 Charts 0x0000000106b88c4c AxisBase.getFormattedLabel(_:) + 160 (AxisBase.swift:149)
9 Charts 0x0000000106b88aa8 implicit closure #2 in implicit closure #1 in AxisBase.getLongestLabel() + 8 (AxisBase.swift:138)
10 Charts 0x0000000106b88aa8 thunk for #escaping #callee_guaranteed (#unowned Int) -> (#owned String) + 8 (:0)
11 Charts 0x0000000106b88aa8 specialized Optional.map(_:) + 8 (:0)
12 Charts 0x0000000106b88aa8 specialized LazyMapSequence.Iterator.next() + 8 (:0)
13 Charts 0x0000000106b88aa8 specialized protocol witness for IteratorProtocol.next() in conformance LazyMapSequence.Iterator + 8 (:0)
I am not sure if it is exactly the same bug, but it is also related to MonthNameFormater.

Given
Swift runtime failure: Index out of range + 0 (:0)
I suspect the crash happens at return symbols[index] - make sure index is in fact a valid index in symbols.

Related

_ArrayBuffer crash

It have a crash that I can't reproduce it on my phone. I call this function in DispatchQueue.concurrentPerform.
Here is my code:
public var arrayLessons: [NotesLessonDataModel] = []
...
func addLessonIfNeeded(lesson: NotesLessonDataModel) {
if lesson.isValid() == false { return }
for item in self.arrayLessons {
if lesson.id == item.id {
return
}
}
self.arrayLessons.append(lesson)
}
...
DispatchQueue.concurrentPerform(iterations: array.count) { (index) in
requestGroup.enter()
// Callback function
self.addLessonIfNeeded(lesson: item)
requestGroup.leave()
}
Here is the firebase crash report:
Crashed: com.apple.root.user-initiated-qos
0 libswiftCore.dylib 0x383c88 _swift_release_dealloc + 24
1 Pocket Papers 0x111594 specialized _ArrayBuffer._consumeAndCreateNew(bufferIsUnique:minimumCapacity:growForAppend:) + 4339750292
2 Pocket Papers 0x91bdc PPNotesManager.addLessonIfNeeded(lesson:) + 4339227612 (<compiler-generated>:4339227612)
3 Pocket Papers 0x927f4 closure #1 in PPNotesManager.getLessonsFromSections(_:exam:completion:) + 146 (PPNotesManager.swift:146)
4 libswiftDispatch.dylib 0x5558 partial apply for thunk for #callee_guaranteed (#unowned Int) -> () + 28
5 libswiftDispatch.dylib 0x5584 thunk for #escaping #callee_guaranteed (#unowned Int) -> () + 32
6 libdispatch.dylib 0x4860 _dispatch_client_callout2 + 20
7 libdispatch.dylib 0x18d7c _dispatch_apply_invoke_and_wait + 160
8 libdispatch.dylib 0x18790 dispatch_apply_f + 728
9 libswiftDispatch.dylib 0x54c8 static OS_dispatch_queue.concurrentPerform(iterations:execute:) + 284
10 Pocket Papers 0xa5e7c closure #1 in NoteViewController.requestLessonDetails() + 161 (PPNotesManager.swift:161)
11 Pocket Papers 0xc240 thunk for #escaping #callee_guaranteed () -> () + 4338680384 (<compiler-generated>:4338680384)
12 libdispatch.dylib 0x2a84 _dispatch_call_block_and_release + 32
13 libdispatch.dylib 0x481c _dispatch_client_callout + 20
14 libdispatch.dylib 0x7968 _dispatch_queue_override_invoke + 756
15 libdispatch.dylib 0x15fe0 _dispatch_root_queue_drain + 388
16 libdispatch.dylib 0x167d8 _dispatch_worker_thread2 + 112
17 libsystem_pthread.dylib 0x3768 _pthread_wqthread + 216
18 libsystem_pthread.dylib 0xa74c start_wqthread + 8

Incorrect strange nonsense making iOS Crashlytics reports due to insufficient free ram?

I have a concerning amount of crashes for my iOS app. When I look at the stacktrace I can follow the flow of the stacktrace up until the 3d line 'fetchDeezerTracks(forAlbum)'. When inspecting my code it should be impossible for this line to be even called. the ApplePlayerManager.play method calls the ApplePlayerManager.fetchTrackIds method which calls a NetworkManager's 'fetchAppleMusicTracks' and this method has a networkRequestResponseHandler to deal with the fetched data, but NEVER ever should/could the 'fetchDeezerTracks' method be called.
My question is the following: Is it possible for Crashlytics to give incorrect reports maybe when the device's free RAM is insufficient? Maybe due to memory leaks or something... I just can't make sense out of the crash report so it would help me a lot to know if something else is at play. Some of the free RAM values of the multiple reports (of the same crash) are the following:
233MB (iPad Air 2), 8MB (iPAad 5th gen), 198MB (iPad Mini 2), 332MB (iPad Mini), 71MB (iPad Air 2), 174MB (iPad 5th gen), 223MB (iPad Air 2), 130MB (iPhone6+), 58MB (iPhoneXR), 381MB (iPhoneXSMax), etc.
Are these normal values?
If these are normal values and crashlytics reports are never "corrupted" then I need to make sense of the stacktrace. I'll add my networking code for reference.
Any help very much appreciated! This is driving me mad and crashes keep on piling up.
Crashed: com.apple.root.background-qos
0 MyApp 0x10045da40 closure #2 in ApplePlayerManager.play(album:withTrack:) + 4302494272 (<compiler-generated>:4302494272)
1 MyApp 0x10045d884 closure #1 in closure #1 in ApplePlayerManager.fetchTrackIds(forAlbum:completionHandler:) + 4302493828 (<compiler-generated>:4302493828)
2 MyApp 0x1004da218 specialized NetworkManager.networkRequestResponseHandler(withResponse:completionHandler:retryHandler:) + 4303004184 (<compiler-generated>:4303004184)
3 MyApp 0x1004d9404 closure #1 in NetworkManager.fetchDeezerTracks(forAlbum:withAccessToken:withCompletionHandler:) + 4303000580
4 MyApp 0x1004d8294 closure #1 in NetworkManager.fetchAppleMusicTracks(forAlbumID:withAccessToken:withCompletionHandler:) + 4302996116
5 Alamofire 0x100a73e64 $s9Alamofire15DownloadRequestC8response5queue0D10Serializer17completionHandlerACXDSo012OS_dispatch_E0CSg_xyAA0B8ResponseVy16SerializedObjectQzGctAA0bkF8ProtocolRzlFyycfU_yycfU_AA0bkF0VyypG_Tg5Tm + 132
6 Alamofire 0x100a79d08 $s9Alamofire15DownloadRequestC8response5queue0D10Serializer17completionHandlerACXDSo012OS_dispatch_E0CSg_xyAA0B8ResponseVy16SerializedObjectQzGctAA0bkF8ProtocolRzlFyycfU_yycfU_AA0bkF0VyypG_Tg5TATm + 36
7 Alamofire 0x100a5b3b0 $sIeg_IeyB_TR + 28
8 libdispatch.dylib 0x18f0eb9a8 _dispatch_call_block_and_release + 24
9 libdispatch.dylib 0x18f0ec524 _dispatch_client_callout + 16
10 libdispatch.dylib 0x18f0a156c _dispatch_root_queue_drain + 684
11 libdispatch.dylib 0x18f0a1bf8 _dispatch_worker_thread2 + 124
12 libsystem_pthread.dylib 0x18f13db38 _pthread_wqthread + 212
13 libsystem_pthread.dylib 0x18f140740 start_wqthread + 8
How I fetch my trackIds (NetworkManager)
func fetchAppleMusicTracks(forAlbumID albumID:String,
withAccessToken accessToken:String,
withCompletionHandler completionHandler:#escaping(JSON?)->Void) {
let url = kAppleMusicAlbumURL + albumID
guard let encodedURL = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else { return completionHandler(nil) }
let headers = [kAppleMusicAuthoritationKey : kAppleMusicBearerKey + accessToken]
Alamofire.request(encodedURL,
method: .get,
parameters: nil,
encoding: URLEncoding.default,
headers: headers).responseJSON(queue: backgroundQueue) {
[weak self]
response in
guard let self = self else { completionHandler(nil); return }
self.networkRequestResponseHandler(withResponse:response,
completionHandler:completionHandler) {
self.fetchAppleMusicTracks(forAlbumID: albumID,
withAccessToken: accessToken,
withCompletionHandler: completionHandler)
}
}
}
my network request handler (NetworkManager):
func networkRequestResponseHandler(withResponse response:DataResponse<Any>,
completionHandler: #escaping(JSON?)->Void,
retryHandler: #escaping()->Void) {
switch response.result {
case .success(let value):
completionHandler(JSON(value))
case .failure(let error):
if self.noConnectionValidator(forError: error, withRetryHandler:retryHandler) { return completionHandler(nil) }
if let status = response.response?.statusCode {
let message = BackendManager.sharedInstance.APIErrorMessageHandler(status: status)
AlertsManager.sharedInstance.displayAlertWithOKButton(forTitle: kGenericErrorTitle,
message: message,
buttonTitle: "Ok")
} else {
AlertsManager.sharedInstance.displayNetworkErrorMessage(withError: error)
}
completionHandler(nil)
}
}
method to fetch tracks (ApplePlayerManager):
private func fetchTrackIds(forAlbum album:String, completionHandler:#escaping([String]?)->Void) {
retrieveAccessToken {
accessToken in
guard let accessToken = accessToken else { completionHandler(nil); return }
NetworkManager.sharedInstance.fetchAppleMusicTracks(forAlbumID: album, withAccessToken: accessToken) {
JSON in
guard let JSON = JSON else {
completionHandler(nil)
return
}
if let tracks = JSON[kAppleMusicDataKey].array?[0][kAppleMusicRelationshipsKey][kAppleMusicTracksKey][kAppleMusicDataKey].array {
let trackIds = tracks.map{ $0[kAppleMusicTrackIdentifierKey].string }.compactMap{ $0 }
completionHandler(trackIds)
} else {
//AlertsManager.sharedInstance.displayAppleMusicCouldNotFetchTracks()
completionHandler(nil)
}
}
}
}
entry-point -> method to play an Apple track (ApplePlayerManager):
override public func play(album:String, withTrack track:Int) {
super.play(album: album, withTrack: track)
guard let streamingManager = streamingManager else { return setup { self.play(album: album, withTrack: track) } }
indexOfLastPlayingItem = track
fetchTrackIds(forAlbum: album) {
[weak self]
trackIds in
guard let self = self else { return }
guard let trackIds = trackIds else {
return //AlertsManager.sharedInstance.displayAppleMusicTracksFetchFailed()
}
self.loadedAlbumTrackIDs = trackIds
if let remainingTracks = self.calculateRemainingTrackList(fromCurrentTrack: track) {
ThreadManager.sharedInstance.executeOnMainThread {
self.play(forStreamingManager: streamingManager, remainingTracks: remainingTracks)
}
}
}
}
EDIT - MORE INFO:
Since my app is using multiple services, I made an abstract PlayerManager singleton class with concrete singleton subclasses for every service. so the PlayerManager.play(track: trackId) will call the correct concrete class method on ApplePlayerManager if beforehand the PlayerManager.service is set to .Apple
I know it looks like somewhere in code the singleton has incorrectly changed service, but again it would not make any sense + I can not reproduce it nor getting a breakpoint hit.
EDIT PART II - ALL THREADS STACKTRACES:
I am getting the suspicion that this might be thread related? Here are all the threads:
Crashed: com.apple.root.background-qos
EXC_BREAKPOINT 0x0000000104cd5a40
Crashed: com.apple.root.background-qos
0 MyApp 0x104cd5a40 closure #2 in ApplePlayerManager.play(album:withTrack:) + 4376304192 (<compiler-generated>:4376304192)
1 MyApp 0x104cd5884 closure #1 in closure #1 in ApplePlayerManager.fetchTrackIds(forAlbum:completionHandler:) + 4376303748 (<compiler-generated>:4376303748)
2 MyApp 0x104d52218 specialized NetworkManager.networkRequestResponseHandler(withResponse:completionHandler:retryHandler:) + 4376814104 (<compiler-generated>:4376814104)
3 MyApp 0x104d51404 closure #1 in NetworkManager.fetchDeezerTracks(forAlbum:withAccessToken:withCompletionHandler:) + 4376810500
4 MyApp 0x104d50294 closure #1 in NetworkManager.fetchAppleMusicTracks(forAlbumID:withAccessToken:withCompletionHandler:) + 4376806036
5 Alamofire 0x105313e64 $s9Alamofire15DownloadRequestC8response5queue0D10Serializer17completionHandlerACXDSo012OS_dispatch_E0CSg_xyAA0B8ResponseVy16SerializedObjectQzGctAA0bkF8ProtocolRzlFyycfU_yycfU_AA0bkF0VyypG_Tg5Tm + 132
6 Alamofire 0x105319d08 $s9Alamofire15DownloadRequestC8response5queue0D10Serializer17completionHandlerACXDSo012OS_dispatch_E0CSg_xyAA0B8ResponseVy16SerializedObjectQzGctAA0bkF8ProtocolRzlFyycfU_yycfU_AA0bkF0VyypG_Tg5TATm + 36
7 Alamofire 0x1052fb3b0 $sIeg_IeyB_TR + 28
8 libdispatch.dylib 0x1b2e9a9a8 _dispatch_call_block_and_release + 24
9 libdispatch.dylib 0x1b2e9b524 _dispatch_client_callout + 16
10 libdispatch.dylib 0x1b2e8165c _dispatch_root_queue_drain + 640
11 libdispatch.dylib 0x1b2e81cd0 _dispatch_worker_thread2 + 112
12 libsystem_pthread.dylib 0x1b2eecb38 _pthread_wqthread + 212
13 libsystem_pthread.dylib 0x1b2eef740 start_wqthread + 8
com.apple.main-thread
com.apple.main-thread
0 libsystem_kernel.dylib 0x1b2fa9198 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x1b2fa860c mach_msg + 72
2 CoreFoundation 0x1b31533b4 __CFRunLoopServiceMachPort + 148
3 CoreFoundation 0x1b314e3e8 __CFRunLoopRun + 1160
4 CoreFoundation 0x1b314dc34 CFRunLoopRunSpecific + 424
5 GraphicsServices 0x1bd29738c GSEventRunModal + 160
6 UIKitCore 0x1b728022c UIApplicationMain + 1932
7 MyApp 0x104cd1060 main + 12 (AppDelegate.swift:12)
8 libdyld.dylib 0x1b2fd5800 start + 4
com.apple.uikit.eventfetch-thread
com.apple.uikit.eventfetch-thread
0 libsystem_kernel.dylib 0x1b2fa9198 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x1b2fa860c mach_msg + 72
2 CoreFoundation 0x1b31533b4 __CFRunLoopServiceMachPort + 148
3 CoreFoundation 0x1b314e3e8 __CFRunLoopRun + 1160
4 CoreFoundation 0x1b314dc34 CFRunLoopRunSpecific + 424
5 Foundation 0x1b3490bcc -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 228
6 Foundation 0x1b3490aac -[NSRunLoop(NSRunLoop) runUntilDate:] + 88
7 UIKitCore 0x1b7322160 -[UIEventFetcher threadMain] + 152
8 Foundation 0x1b35bf9d0 __NSThread__start__ + 848
9 libsystem_pthread.dylib 0x1b2eebd98 _pthread_start + 156
10 libsystem_pthread.dylib 0x1b2eef74c thread_start + 8
com.twitter.crashlytics.ios.MachExceptionServer
com.twitter.crashlytics.ios.MachExceptionServer
0 MyApp 0x104d7b448 CLSProcessRecordAllThreads + 4376982600
1 MyApp 0x104d7b830 CLSProcessRecordAllThreads + 4376983600
2 MyApp 0x104d6b09c CLSHandler + 4376916124
3 MyApp 0x104d66ac4 CLSMachExceptionServer + 4376898244
4 libsystem_pthread.dylib 0x1b2eebd98 _pthread_start + 156
5 libsystem_pthread.dylib 0x1b2eef74c thread_start + 8
com.apple.root.background-qos
com.apple.root.background-qos
0 libsystem_malloc.dylib 0x1b2ec6154 calloc + 98
1 CoreFoundation 0x1b31e23c4 __CFAllocateObject + 20
2 CoreFoundation 0x1b3205b38 __NSDictionaryM_new + 128
3 Foundation 0x1b3586e68 _encodeObject + 964
4 Foundation 0x1b34a2334 -[NSKeyedArchiver _encodeArrayOfObjects:forKey:] + 360
5 Foundation 0x1b3586f58 _encodeObject + 1204
6 MyApp 0x104d372f8 Album.encode(with:) + 4376703736 (<compiler-generated>:4376703736)
7 MyApp 0x104d37354 #objc Album.encode(with:) + 4376703828 (<compiler-generated>:4376703828)
8 Foundation 0x1b3586f58 _encodeObject + 1204
9 Foundation 0x1b34a2334 -[NSKeyedArchiver _encodeArrayOfObjects:forKey:] + 360
10 Foundation 0x1b3586f58 _encodeObject + 1204
11 MyApp 0x104cec884 Series.encode(with:) + 4376397956 (<compiler-generated>:4376397956)
12 MyApp 0x104cec93c #objc Series.encode(with:) + 4376398140 (<compiler-generated>:4376398140)
13 Foundation 0x1b3586f58 _encodeObject + 1204
14 Foundation 0x1b34a2334 -[NSKeyedArchiver _encodeArrayOfObjects:forKey:] + 360
15 Foundation 0x1b3586f58 _encodeObject + 1204
16 MyApp 0x104cfcaf0 User.encode(with:) + 4376464112 (<compiler-generated>:4376464112)
17 MyApp 0x104cfcc64 #objc User.encode(with:) + 4376464484 (<compiler-generated>:4376464484)
18 Foundation 0x1b3586f58 _encodeObject + 1204
19 Foundation 0x1b34a2334 -[NSKeyedArchiver _encodeArrayOfObjects:forKey:] + 360
20 Foundation 0x1b34ccea0 -[NSDictionary(NSDictionary) encodeWithCoder:] + 876
21 Foundation 0x1b3586f58 _encodeObject + 1204
22 Foundation 0x1b34ed5c8 +[NSKeyedArchiver archivedDataWithRootObject:] + 124
23 SwiftyUserDefaults 0x105c9b8c4 $sSo14NSUserDefaultsC010SwiftyUserB0E7archiveyyAC0B3KeyCyxSgG_AGtlF + 292
24 MyApp 0x104d3a7f8 closure #1 in UserManager._cachedSavedUsers.didset + 4376717304 (<compiler-generated>:4376717304)
25 MyApp 0x104d05e10 partial apply for closure #1 in ThreadManager.executeOnMainThread(afterSeconds:withBlock:) + 4376501776 (<compiler-generated>:4376501776)
26 MyApp 0x104d5fc98 thunk for #escaping #callee_guaranteed () -> () + 4376870040 (<compiler-generated>:4376870040)
27 libdispatch.dylib 0x1b2e9a9a8 _dispatch_call_block_and_release + 24
28 libdispatch.dylib 0x1b2e9b524 _dispatch_client_callout + 16
29 libdispatch.dylib 0x1b2e8165c _dispatch_root_queue_drain + 640
30 libdispatch.dylib 0x1b2e81cd0 _dispatch_worker_thread2 + 112
31 libsystem_pthread.dylib 0x1b2eecb38 _pthread_wqthread + 212
32 libsystem_pthread.dylib 0x1b2eef740 start_wqthread + 8
com.apple.NSURLConnectionLoader
com.apple.NSURLConnectionLoader
0 libsystem_kernel.dylib 0x1b2fa9198 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x1b2fa860c mach_msg + 72
2 CoreFoundation 0x1b31533b4 __CFRunLoopServiceMachPort + 148
3 CoreFoundation 0x1b314e3e8 __CFRunLoopRun + 1160
4 CoreFoundation 0x1b314dc34 CFRunLoopRunSpecific + 424
5 CFNetwork 0x1b6412c44 (Missing)
6 Foundation 0x1b35bf9d0 __NSThread__start__ + 848
7 libsystem_pthread.dylib 0x1b2eebd98 _pthread_start + 156
8 libsystem_pthread.dylib 0x1b2eef74c thread_start + 8
com.apple.root.background-qos
com.apple.root.background-qos
0 libsystem_platform.dylib 0x1b2edd948 _platform_memmove + 88
1 libsystem_malloc.dylib 0x1b2ebc628 szone_realloc + 544
2 libsystem_malloc.dylib 0x1b2ec5a9c malloc_zone_realloc + 168
3 libsystem_malloc.dylib 0x1b2ec625c realloc + 196
4 CoreFoundation 0x1b30f3948 __CFSafelyReallocate + 28
5 Foundation 0x1b3555ea0 _NSMutableDataGrowBytes + 344
6 Foundation 0x1b34a2a34 -[NSConcreteMutableData appendBytes:length:] + 340
7 CoreFoundation 0x1b30fcfac writeBytes + 164
8 CoreFoundation 0x1b30fa01c bufferWrite + 320
9 CoreFoundation 0x1b30fd144 _appendString + 264
10 CoreFoundation 0x1b30fa1b8 _appendObject + 348
11 CoreFoundation 0x1b30f99fc __CFBinaryPlistWriteOrPresize + 528
12 Foundation 0x1b34a27d0 -[NSKeyedArchiver finishEncoding] + 528
13 Foundation 0x1b34ed5d8 +[NSKeyedArchiver archivedDataWithRootObject:] + 140
14 SwiftyUserDefaults 0x105c9b8c4 $sSo14NSUserDefaultsC010SwiftyUserB0E7archiveyyAC0B3KeyCyxSgG_AGtlF + 292
15 MyApp 0x104d3a3bc closure #1 in UserManager._cachedActiveUser.didset + 4376716220 (<compiler-generated>:4376716220)
16 MyApp 0x104d05e10 partial apply for closure #1 in ThreadManager.executeOnMainThread(afterSeconds:withBlock:) + 4376501776 (<compiler-generated>:4376501776)
17 MyApp 0x104d5fc98 thunk for #escaping #callee_guaranteed () -> () + 4376870040 (<compiler-generated>:4376870040)
18 libdispatch.dylib 0x1b2e9a9a8 _dispatch_call_block_and_release + 24
19 libdispatch.dylib 0x1b2e9b524 _dispatch_client_callout + 16
20 libdispatch.dylib 0x1b2e8165c _dispatch_root_queue_drain + 640
21 libdispatch.dylib 0x1b2e81cd0 _dispatch_worker_thread2 + 112
22 libsystem_pthread.dylib 0x1b2eecb38 _pthread_wqthread + 212
23 libsystem_pthread.dylib 0x1b2eef740 start_wqthread + 8
AVAudioSession Notify Thread
AVAudioSession Notify Thread
0 libsystem_kernel.dylib 0x1b2fa9198 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x1b2fa860c mach_msg + 72
2 CoreFoundation 0x1b31533b4 __CFRunLoopServiceMachPort + 148
3 CoreFoundation 0x1b314e3e8 __CFRunLoopRun + 1160
4 CoreFoundation 0x1b314dc34 CFRunLoopRunSpecific + 424
5 AVFAudio 0x1bfef65dc GenericRunLoopThread::Entry(void*) + 156
6 AVFAudio 0x1bff47300 CAPThread::Entry(CAPThread*) + 204
7 libsystem_pthread.dylib 0x1b2eebd98 _pthread_start + 156
8 libsystem_pthread.dylib 0x1b2eef74c thread_start + 8
Thread #1
Thread
0 libsystem_kernel.dylib 0x1b2fcb940 __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x1b2eecbc0 _pthread_wqthread + 348
2 libsystem_pthread.dylib 0x1b2eef740 start_wqthread + 8
Thread #2
Thread
0 libsystem_pthread.dylib 0x1b2eef738 start_wqthread + 190
com.apple.root.background-qos
com.apple.root.background-qos
0 CoreFoundation 0x1b3206828 mdict_rehashd + 244
1 CoreFoundation 0x1b30b8f00 -[__NSDictionaryM __setObject:forKey:] + 888
2 Foundation 0x1b35876d8 addValueToTopContainerE + 128
3 Foundation 0x1b3587180 _encodeObject + 1756
4 Foundation 0x1b34a2334 -[NSKeyedArchiver _encodeArrayOfObjects:forKey:] + 360
5 Foundation 0x1b3586f58 _encodeObject + 1204
6 MyApp 0x104d372f8 Album.encode(with:) + 4376703736 (<compiler-generated>:4376703736)
7 MyApp 0x104d37354 #objc Album.encode(with:) + 4376703828 (<compiler-generated>:4376703828)
8 Foundation 0x1b3586f58 _encodeObject + 1204
9 Foundation 0x1b34a2334 -[NSKeyedArchiver _encodeArrayOfObjects:forKey:] + 360
10 Foundation 0x1b3586f58 _encodeObject + 1204
11 MyApp 0x104cec884 Series.encode(with:) + 4376397956 (<compiler-generated>:4376397956)
12 MyApp 0x104cec93c #objc Series.encode(with:) + 4376398140 (<compiler-generated>:4376398140)
13 Foundation 0x1b3586f58 _encodeObject + 1204
14 Foundation 0x1b34a2334 -[NSKeyedArchiver _encodeArrayOfObjects:forKey:] + 360
15 Foundation 0x1b3586f58 _encodeObject + 1204
16 MyApp 0x104cfcaf0 User.encode(with:) + 4376464112 (<compiler-generated>:4376464112)
17 MyApp 0x104cfcc64 #objc User.encode(with:) + 4376464484 (<compiler-generated>:4376464484)
18 Foundation 0x1b3586f58 _encodeObject + 1204
19 Foundation 0x1b34a2334 -[NSKeyedArchiver _encodeArrayOfObjects:forKey:] + 360
20 Foundation 0x1b34ccea0 -[NSDictionary(NSDictionary) encodeWithCoder:] + 876
21 Foundation 0x1b3586f58 _encodeObject + 1204
22 Foundation 0x1b34ed5c8 +[NSKeyedArchiver archivedDataWithRootObject:] + 124
23 SwiftyUserDefaults 0x105c9b8c4 $sSo14NSUserDefaultsC010SwiftyUserB0E7archiveyyAC0B3KeyCyxSgG_AGtlF + 292
24 MyApp 0x104d3a7f8 closure #1 in UserManager._cachedSavedUsers.didset + 4376717304 (<compiler-generated>:4376717304)
25 MyApp 0x104d05e10 partial apply for closure #1 in ThreadManager.executeOnMainThread(afterSeconds:withBlock:) + 4376501776 (<compiler-generated>:4376501776)
26 MyApp 0x104d5fc98 thunk for #escaping #callee_guaranteed () -> () + 4376870040 (<compiler-generated>:4376870040)
27 libdispatch.dylib 0x1b2e9a9a8 _dispatch_call_block_and_release + 24
28 libdispatch.dylib 0x1b2e9b524 _dispatch_client_callout + 16
29 libdispatch.dylib 0x1b2e8165c _dispatch_root_queue_drain + 640
30 libdispatch.dylib 0x1b2e81cd0 _dispatch_worker_thread2 + 112
31 libsystem_pthread.dylib 0x1b2eecb38 _pthread_wqthread + 212
32 libsystem_pthread.dylib 0x1b2eef740 start_wqthread + 8
com.apple.root.background-qos
com.apple.root.background-qos
0 libobjc.A.dylib 0x1b2f12aa8 objc_release + 24
1 libswiftCore.dylib 0x1c0914680 swift_arrayDestroy + 68
2 libswiftCore.dylib 0x1c06d38c8 _DictionaryStorage.deinit + 360
3 libswiftCore.dylib 0x1c06d394c _DictionaryStorage.__deallocating_deinit + 12
4 libswiftCore.dylib 0x1c091e320 _swift_release_dealloc + 28
5 SwiftyJSON 0x105c396d0 $s10SwiftyJSON6unwrap33_4625CC38AABF536BB76490A35D7233C9LLyypypF + 1400
6 SwiftyJSON 0x105c394a4 $s10SwiftyJSON6unwrap33_4625CC38AABF536BB76490A35D7233C9LLyypypF + 844
7 SwiftyJSON 0x105c395d8 $s10SwiftyJSON6unwrap33_4625CC38AABF536BB76490A35D7233C9LLyypypF + 1152
8 SwiftyJSON 0x105c394a4 $s10SwiftyJSON6unwrap33_4625CC38AABF536BB76490A35D7233C9LLyypypF + 844
9 SwiftyJSON 0x105c394a4 $s10SwiftyJSON6unwrap33_4625CC38AABF536BB76490A35D7233C9LLyypypF + 844
10 SwiftyJSON 0x105c394a4 $s10SwiftyJSON6unwrap33_4625CC38AABF536BB76490A35D7233C9LLyypypF + 844
11 SwiftyJSON 0x105c395d8 $s10SwiftyJSON6unwrap33_4625CC38AABF536BB76490A35D7233C9LLyypypF + 1152
12 SwiftyJSON 0x105c394a4 $s10SwiftyJSON6unwrap33_4625CC38AABF536BB76490A35D7233C9LLyypypF + 844
13 SwiftyJSON 0x105c383e4 $s10SwiftyJSON0B0V6objectypvs + 44
14 SwiftyJSON 0x105c49ccc $s10SwiftyJSON0B0V10jsonObjectACyp_tc33_4625CC38AABF536BB76490A35D7233C9LlfCTf4nd_n + 164
15 SwiftyJSON 0x105c49f00 $s10SwiftyJSON0B0VyACypcfCTf4nd_n + 152
16 SwiftyJSON 0x105c381ac $s10SwiftyJSON0B0VyACypcfC + 28
17 MyApp 0x104d521e4 specialized NetworkManager.networkRequestResponseHandler(withResponse:completionHandler:retryHandler:) + 51 (NetworkManager.swift:51)
18 MyApp 0x104d51404 closure #1 in NetworkManager.fetchDeezerTracks(forAlbum:withAccessToken:withCompletionHandler:) + 4376810500
19 MyApp 0x104d50294 closure #1 in NetworkManager.fetchAppleMusicTracks(forAlbumID:withAccessToken:withCompletionHandler:) + 4376806036
20 Alamofire 0x105313e64 $s9Alamofire15DownloadRequestC8response5queue0D10Serializer17completionHandlerACXDSo012OS_dispatch_E0CSg_xyAA0B8ResponseVy16SerializedObjectQzGctAA0bkF8ProtocolRzlFyycfU_yycfU_AA0bkF0VyypG_Tg5Tm + 132
21 Alamofire 0x105319d08 $s9Alamofire15DownloadRequestC8response5queue0D10Serializer17completionHandlerACXDSo012OS_dispatch_E0CSg_xyAA0B8ResponseVy16SerializedObjectQzGctAA0bkF8ProtocolRzlFyycfU_yycfU_AA0bkF0VyypG_Tg5TATm + 36
22 Alamofire 0x1052fb3b0 $sIeg_IeyB_TR + 28
23 libdispatch.dylib 0x1b2e9a9a8 _dispatch_call_block_and_release + 24
24 libdispatch.dylib 0x1b2e9b524 _dispatch_client_callout + 16
25 libdispatch.dylib 0x1b2e8165c _dispatch_root_queue_drain + 640
26 libdispatch.dylib 0x1b2e81cd0 _dispatch_worker_thread2 + 112
27 libsystem_pthread.dylib 0x1b2eecb38 _pthread_wqthread + 212
28 libsystem_pthread.dylib 0x1b2eef740 start_wqthread + 8
com.google.fira.worker
com.google.fira.worker
0 libsqlite3.dylib 0x1b4df32a8 sqlite3_exec + 26552
1 libsqlite3.dylib 0x1b4dee810 sqlite3_exec + 7456
2 libsqlite3.dylib 0x1b4ded6fc sqlite3_exec + 3084
3 libsqlite3.dylib 0x1b4decc3c sqlite3_exec + 332
4 MyApp 0x104e1d0cc -[APMSqliteStore beginTransaction] + 4377645260
5 MyApp 0x104e1cf18 -[APMSqliteStore performTransactionWithError:block:] + 4377644824
6 MyApp 0x104dd9444 -[APMDatabase performTransaction:] + 4377367620
7 MyApp 0x104df2a5c -[APMMeasurement writeEventOnWorkerQueue:] + 4377471580
8 MyApp 0x104df2280 -[APMMeasurement handleEventOnWorkerQueue:] + 4377469568
9 MyApp 0x104df1500 __27-[APMMeasurement logEvent:]_block_invoke + 4377466112
10 MyApp 0x104e06f50 __51-[APMScheduler scheduleOnWorkerQueueBlockID:block:]_block_invoke + 4377554768
11 libdispatch.dylib 0x1b2e9a9a8 _dispatch_call_block_and_release + 24
12 libdispatch.dylib 0x1b2e9b524 _dispatch_client_callout + 16
13 libdispatch.dylib 0x1b2e78b3c _dispatch_lane_serial_drain$VARIANT$armv81 + 564
14 libdispatch.dylib 0x1b2e7954c _dispatch_lane_invoke$VARIANT$armv81 + 396
15 libdispatch.dylib 0x1b2e8284c _dispatch_workloop_worker_thread + 580
16 libsystem_pthread.dylib 0x1b2eecb74 _pthread_wqthread + 272
17 libsystem_pthread.dylib 0x1b2eef740 start_wqthread + 8
(Just a guess)
This reeks of threading issues (you can get odd threading cashes if you try and access/manipulate the same object from different threads, and looking at your code you have escaping closures on escaping closures all over the place), looking through your crash log maybe it has something to do with the UserManager seeing: this UserManager._cachedSavedUsers.didset twice and UserManager._cachedActiveUser.didset too, always followed by some writes.
Even shows up on the thread labeled com.twitter.crashlytics.ios.MachExceptionServer but that could be for any reason, just suspicious given all this other stuff too and that crashlytics is your crash reporting tool..
App will definitely crash (intermittently) if there's some encoding / property manipulation happening on this user manager / an app-wide cache and its not being accessed in a thread safe way

IOS Unknown crash :- BUG IN CLIENT OF LIBPLATFORM: Trying to recursively lock an os_unfair_lock

Here is the code where the crash had occurred :-
private func dispatchMessageImmediately(topicName : String, mqttMessage : MQTTMessage){
AppDelegate.getAppDelegate().log.debug("Message: \(String(describing: mqttMessage.payloadString))")
let listener = self.topicToListenerMap?[topicName]
if listener != nil {
DispatchQueue.main.async(execute: { () -> Void in
MessageDispatchUtils.dispatchMessageToListeners(topicName: topicName, mqttMessage: mqttMessage, topicListener: listener!)
})
}
}
The Xcode version I am using is 9.3. My os version is iOS 11.4.1 Device is iPhone 5s. The crash is caused in libswift.dylib
Here is the crash report for the crash.Any help? Thanks in advance
Crashed: com.apple.main-thread
0 libsystem_platform.dylib 0x18358de38 _os_unfair_lock_recursive_abort + 36
1 libsystem_platform.dylib 0x18358ebb8 _os_unfair_lock_lock_slow + 264
2 libobjc.A.dylib 0x182b45720 objc_object::sidetable_clearDeallocating() + 104
3 libobjc.A.dylib 0x182b349d8 objc_destructInstance + 140
4 libswiftCore.dylib 0x10263ec0c swift_deallocClassInstance + 32
5 libswiftCore.dylib 0x10263eb4c _swift_release_dealloc + 28
6 Razorpay 0x1020f09b0 _T08Razorpay0A13UtilFunctionsC24handleUnhandledExceptionys5Int32V16havingSignalCode_SS03andI4NametFZTf4nnd_n + 248
7 libsystem_platform.dylib 0x183590b48 _sigtramp + 36
8 libobjc.A.dylib 0x182b45740 objc_object::sidetable_clearDeallocating() + 136
9 libobjc.A.dylib 0x182b45740 objc_object::sidetable_clearDeallocating() + 136
10 libobjc.A.dylib 0x182b349d8 objc_destructInstance + 140
11 libswiftCore.dylib 0x10263ec0c swift_deallocClassInstance + 32
12 libswiftCore.dylib 0x10263eb4c _swift_release_dealloc + 28
13 libswiftCore.dylib 0x1025750ec specialized String.debugDescription.getter + 4580
14 libswiftCore.dylib 0x1024bd66c protocol witness for CustomDebugStringConvertible.debugDescription.getter in conformance String + 290904
15 libswiftCore.dylib 0x1023da008 _debugPrint_unlocked<A, B>(_:_:) + 252544
16 libswiftCore.dylib 0x10257bc04 specialized _debugPrint<A>(_:separator:terminator:to:) + 31996
17 libswiftCore.dylib 0x10245a8fc Optional.debugDescription.getter + 68296
18 libswiftCore.dylib 0x10245aa4c protocol witness for CustomStringConvertible.description.getter in conformance <A> A! + 68632
19 libswiftCore.dylib 0x10257bf44 specialized _print_unlocked<A, B>(_:_:) + 32828
20 Quickride 0x10090c37c implicit closure #1 in EventServiceProxy.dispatchMessageImmediately(topicName:mqttMessage:) (EventServiceProxy.swift:238)
21 Quickride 0x1009186c4 partial apply for implicit closure #1 in EventServiceProxy.onNewMessageArrived(mqttMessage:) + 4314498756
22 XCGLogger 0x1021b86f4 _T09XCGLoggerAAC5loglnyAB5LevelO_SS12functionNameSS04fileE0Si10lineNumbers10DictionaryVySSypG8userInfoypSgyc7closuretFTf4ngXgXnggn_n + 232
23 XCGLogger 0x1021b3bac _T09XCGLoggerAAC7verboseyypSgyXK_s12StaticStringV12functionNameAF04fileF0Si10lineNumbers10DictionaryVySSypG8userInfotFTm + 500
24 XCGLogger 0x1021b2aa8 _T09XCGLoggerAAC5debugyypSgyXK_s12StaticStringV12functionNameAF04fileF0Si10lineNumbers10DictionaryVySSypG8userInfotF + 32
25 Quickride 0x100915144 specialized EventServiceProxy.dispatchMessageImmediately(topicName:mqttMessage:) (EventServiceProxy.swift:238)
26 Quickride 0x100916918 specialized EventServiceProxy.onNewMessageArrived(mqttMessage:) (EventServiceProxy.swift:145)
27 Quickride 0x10090d8c8 protocol witness for MqttCallback.onNewMessageArrived(mqttMessage:) in conformance EventServiceProxy (EventServiceProxy.swift)
28 Quickride 0x100cf309c specialized closure #1 in closure #4 in EventServiceConnection.createMqttConfig() (EventServiceConnection.swift:100)
29 Quickride 0x100cf29f4 partial apply for closure #1 in closure #4 in EventServiceConnection.createMqttConfig() (EventServiceConnection.swift)
30 Quickride 0x1008c19fc thunk for #callee_owned () -> () (RideManagementModuleSessonHandler.swift)
31 libdispatch.dylib 0x183260aa0 _dispatch_call_block_and_release + 24
32 libdispatch.dylib 0x183260a60 _dispatch_client_callout + 16
33 libdispatch.dylib 0x18326d65c _dispatch_main_queue_callback_4CF$VARIANT$mp + 1012
34 CoreFoundation 0x183917070 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
35 CoreFoundation 0x183914bc8 __CFRunLoopRun + 2272
36 CoreFoundation 0x183834da8 CFRunLoopRunSpecific + 552
37 GraphicsServices 0x18581a020 GSEventRunModal + 100
38 UIKit 0x18d854758 UIApplicationMain + 236
39 Quickride 0x1007d4bf0 main (AppDelegate.swift:26)
40 libdyld.dylib 0x1832c5fc0 start + 4

Why might FMDB be crashing with two distinct instances on two separate threads?

I have instantiated and am using two FMDatabase instances, each one in a different class, with paths to two distinct databases.
From what I understand this usage shouldn't be the cause of the crash on the main thread below, but I may be mistaken. If it is indeed the reason behind the crash, could someone help me understand why?
Main thread:
Crashed: com.apple.main-thread
0 libsqlite3.dylib 0x18461d9f0 (null) + 972
1 libsqlite3.dylib 0x18461d9c4 (null) + 928
2 libsqlite3.dylib 0x1846a4644 (null) + 37328
3 libsqlite3.dylib 0x1846acb14 (null) + 71328
4 libsqlite3.dylib 0x1846abdb4 (null) + 67904
5 libsqlite3.dylib 0x1846370c4 (null) + 9180
6 libsqlite3.dylib 0x184635b7c sqlite3_step + 3732
[*CRASH*]
7 FMDB 0x100d55950 -[FMResultSet nextWithError:] (FMResultSet.m:165)
8 ZiiZii 0x100713d68 specialized static CatalogManager.countItems() -> Int (CatalogManager.swift:157)
9 ZiiZii 0x10079ad34 specialized CustomerInfoCell.render(Customer!, isCatalogAvailable : Bool?, for : UIViewController, at : IndexPath?) -> () (CatalogManager.swift)
10 ZiiZii 0x1007a7a34 specialized MainController.(viewDidLoad() -> ()).(closure #1).(closure #2).(closure #2).(closure #1).(closure #1) (MainController.swift)
11 ZiiZii 0x1007afbc0 partial apply for MainController.(viewDidLoad() -> ()).(closure #1).(closure #2).(closure #2).(closure #1).(closure #2) + 4304190400
12 ZiiZii 0x10084cf20 DynamicTableRow.(show(String, onRender : (UITableViewCell) -> ()) -> ()).(closure #1) (DynamicTableRow.swift:111)
13 ZiiZii 0x1008661b8 specialized DynamicTableSection.cellForRow(UITableView, rowIndex : Int) -> UITableViewCell (DynamicTableRow.swift:157)
14 ZiiZii 0x100676d58 specialized DynamicTable.tableView(UITableView, cellForRowAt : IndexPath) -> UITableViewCell (DynamicTableSection.swift)
15 ZiiZii 0x100675edc #objc DynamicTable.tableView(UITableView, cellForRowAt : IndexPath) -> UITableViewCell (DynamicTable.swift)
16 UIKit 0x18d96b948 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 664
17 UIKit 0x18d96beac -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 80
18 UIKit 0x18d813934 -[_UITableViewUpdateSupport(Private) _setupAnimationsForNewlyInsertedCells] + 5188
19 UIKit 0x18d80f9f0 -[_UITableViewUpdateSupport _setupAnimations] + 208
20 UIKit 0x18d80f3a8 -[UITableView _updateWithItems:updateSupport:] + 2456
21 UIKit 0x18d7f6fe0 -[UITableView _endCellAnimationsWithContext:] + 15456
22 UIKit 0x18d7f328c -[UITableView endUpdates] + 92
23 ZiiZii 0x100675948 DynamicTable.performUpdates() -> () (DynamicTable.swift:213)
24 ZiiZii 0x1006e935c DynamicTableViewController.refresh(Bool) -> () (DynamicTableViewController.swift)
25 ZiiZii 0x1007a0ba4 MainController.viewWillAppear(Bool) -> () (MainController.swift:421)
26 ZiiZii 0x1007a0c00 #objc MainController.viewWillAppear(Bool) -> () (MainController.swift)
27 UIKit 0x18d64996c -[UIViewController _setViewAppearState:isAnimating:] + 628
28 UIKit 0x18d6496e0 -[UIViewController __viewWillAppear:] + 156
29 UIKit 0x18d6d46c8 -[UINavigationController viewWillAppear:] + 440
30 UIKit 0x18d64996c -[UIViewController _setViewAppearState:isAnimating:] + 628
31 UIKit 0x18d6496e0 -[UIViewController __viewWillAppear:] + 156
32 UIKit 0x18d97c734 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke + 1152
33 UIKit 0x18d8a0f74 _runAfterCACommitDeferredBlocks + 292
34 UIKit 0x18d894318 _cleanUpAfterCAFlushAndRunDeferredBlocks + 288
35 UIKit 0x18d623ac8 _afterCACommitHandler + 132
36 CoreFoundation 0x1841a1848 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
37 CoreFoundation 0x18419f200 __CFRunLoopDoObservers + 412
38 CoreFoundation 0x18419f7bc __CFRunLoopRun + 1292
39 CoreFoundation 0x1840bffb8 CFRunLoopRunSpecific + 436
40 GraphicsServices 0x185f57f84 GSEventRunModal + 100
41 UIKit 0x18d6942f4 UIApplicationMain + 208
42 ZiiZii 0x10064fc20 main (AppDelegate.swift:23)
43 libdyld.dylib 0x183be256c start + 4
Background thread:
com.apple.root.default-qos
0 libsystem_kernel.dylib 0x183cf2ebc fsync + 8
1 libsqlite3.dylib 0x18465ec58 (null) + 59172
2 libsqlite3.dylib 0x18465e50c (null) + 57304
3 libsqlite3.dylib 0x18464addc (null) + 21892
4 libsqlite3.dylib 0x1846181b0 (null) + 3472
5 libsqlite3.dylib 0x184644540 (null) + 63576
6 libsqlite3.dylib 0x184635b7c sqlite3_step + 3732
7 FMDB 0x100d50ae0 -[FMDatabase executeUpdate:error:withArgumentsInArray:orDictionary:orVAList:] (FMDatabase.m:1104)
8 FMDB 0x100d50f1c -[FMDatabase executeUpdate:withArgumentsInArray:] (FMDatabase.m:1198)
9 ZiiZii 0x100793000 specialized static LabelsManager.createLabel(format : LabelFormat?, item : CatalogItem?) -> Label? (LabelsManager.swift:66)
10 ZiiZii 0x1007beebc specialized MainPrintingFeature.(lookupBarcode(String, String, (ScannerResponse) -> ()) -> ()).(closure #1) (LabelsManager.swift)
11 ZiiZii 0x1007bcb10 partial apply for MainPrintingFeature.(lookupBarcode(String, String, (ScannerResponse) -> ()) -> ()).(closure #1) (MainPrintingFeature.swift)
12 libdispatch.dylib 0x183b7d088 _dispatch_call_block_and_release + 24
13 libdispatch.dylib 0x183b7d048 _dispatch_client_callout + 16
14 libdispatch.dylib 0x183b84090 _dispatch_queue_override_invoke$VARIANT$mp + 716
15 libdispatch.dylib 0x183b8a1c8 _dispatch_root_queue_drain + 596
16 libdispatch.dylib 0x183b89f10 _dispatch_worker_thread3 + 120
17 libsystem_pthread.dylib 0x183e23120 _pthread_wqthread + 1268
18 libsystem_pthread.dylib 0x183e22c20 start_wqthread + 4

Swift iOS EKEventStore : Fetching atendees from EKEvent causes sometimes to crash with NSInvalidArgumentException

I try to load all Calendar events by using block and sometimes (0.5% rate) I get NSInvalidArgumentException that causes to crash:
var allCals = _eventStore.calendarsForEntityType(EKEntityTypeEvent)
var predicate:NSPredicate! = _eventStore.predicateForEventsWithStartDate(yearsAgo, endDate:toAgo, calendars:allCals)
_eventStore.enumerateEventsMatchingPredicate(predicate, usingBlock:{
(event:EKEvent!, stop:UnsafeMutablePointer<ObjCBool>) in
if (event.title != nil
&& event.calendar != nil
&& event.calendar.calendarIdentifier != nil
&& event.lastModifiedDate != nil
){
if event.attendees != nil{ // < -- SOMETIMES LEADS TO CRASH!!
//...
}
else{ // standalone
//...
}
}
//......
})// end block
Full stack trace: [thread crash + Exception]
Thread : Fatal Exception: NSInvalidArgumentException
0 CoreFoundation 0x2917649f __exceptionPreprocess + 126
1 libobjc.A.dylib 0x36970c8b objc_exception_throw + 38
2 CoreFoundation 0x29096291 -[__NSSetM addObject:] + 608
3 EventKit 0x29b4eacf -[EKPersistentObject primitiveRelationValueForKey:] + 502
4 Foundation 0x29dc1617 -[NSObject(NSKeyValueCoding) valueForKey:] + 202
5 EventKit 0x29b5afc5 -[EKObjectToManyRelation _loadedItems] + 120
6 EventKit 0x29b5aef3 -[EKObjectToManyRelation _effectiveItems] + 102
7 EventKit 0x29b5ae69 -[EKObjectToManyRelation items] + 20
8 EventKit 0x29b5d179 -[EKCalendarItem attendees] + 36
9 MyApp 0x000d8c78 _TTSf2n_n_n_n_n_d_i_n_n___TFFC8MyApp17WmBuildGroupsTask14doInBackgroundFS0_FT_T_U_FTGSqCSo7EKEvent_GVSs20UnsafeMutablePointerV10ObjectiveC8ObjCBool__T_ (WmBuildGroupsTask.swift:421)
10 MyApp 0x000d3f3c _TPA__TTSf2n_n_n_n_n_d_i_n_n___TFFC8MyApp17WmBuildGroupsTask14doInBackgroundFS0_FT_T_U_FTGSqCSo7EKEvent_GVSs20UnsafeMutablePointerV10ObjectiveC8ObjCBool__T_ (WmBuildGroupsTask.swift)
11 MyApp 0x000d96b8 reabstraction thunk helper from #callee_owned (#owned Swift.ImplicitlyUnwrappedOptional<ObjectiveC.EKEvent>, #unowned Swift.UnsafeMutablePointer<ObjectiveC.ObjCBool>) -> (#unowned ()) to #callee_unowned #objc_block (#unowned Swift.ImplicitlyUnwrappedOptional<ObjectiveC.EKEvent>, #unowned Swift.UnsafeMutablePointer<ObjectiveC.ObjCBool>) -> (#unowned ()) (WmBuildGroupsTask.swift)
12 EventKit 0x29ba72a7 __60-[EKEventStore enumerateEventsMatchingPredicate:usingBlock:]_block_invoke + 130
13 EventKit 0x29bad6af __41-[EKPredicateSearch startWithCompletion:]_block_invoke_2 + 690
14 libdispatch.dylib 0x36ed07bb _dispatch_call_block_and_release + 10
15 libdispatch.dylib 0x36ed9dab _dispatch_root_queue_drain + 866
16 libdispatch.dylib 0x36edacd7 _dispatch_worker_thread3 + 94
17 libsystem_pthread.dylib 0x37031e31 _pthread_wqthread + 668
18 libsystem_pthread.dylib 0x37031b84 start_wqthread + 8
Thread : Crashed: com.apple.root.default-qos
0 libsystem_kernel.dylib 0x36fb6dfc __pthread_kill + 8
1 libsystem_pthread.dylib 0x37034d37 pthread_kill + 62
2 libsystem_c.dylib 0x36f56909 abort + 76
3 libc++abi.dylib 0x362919c9 __cxa_bad_cast
4 libc++abi.dylib 0x362ab671 default_unexpected_handler()
5 libobjc.A.dylib 0x36970f25 _objc_terminate() + 192
6 libc++abi.dylib 0x362a8de3 std::__terminate(void (*)()) + 78
7 libc++abi.dylib 0x362a85a9 __cxxabiv1::exception_cleanup_func(_Unwind_Reason_Code, _Unwind_Exception*)
8 libobjc.A.dylib 0x36970d5f objc_exception_throw + 250
9 CoreFoundation 0x29096291 -[__NSSetM addObject:] + 608
10 EventKit 0x29b4eacf -[EKPersistentObject primitiveRelationValueForKey:] + 502
11 Foundation 0x29dc1617 -[NSObject(NSKeyValueCoding) valueForKey:] + 202
12 EventKit 0x29b5afc5 -[EKObjectToManyRelation _loadedItems] + 120
13 EventKit 0x29b5aef3 -[EKObjectToManyRelation _effectiveItems] + 102
14 EventKit 0x29b5ae69 -[EKObjectToManyRelation items] + 20
15 EventKit 0x29b5d179 -[EKCalendarItem attendees] + 36
16 MyApp 0x000d8c78 _TTSf2n_n_n_n_n_d_i_n_n___TFFC8MyApp17WmBuildGroupsTask14doInBackgroundFS0_FT_T_U_FTGSqCSo7EKEvent_GVSs20UnsafeMutablePointerV10ObjectiveC8ObjCBool__T_ (WmBuildGroupsTask.swift:421)
17 MyApp 0x000d3f3c _TPA__TTSf2n_n_n_n_n_d_i_n_n___TFFC8MyApp17WmBuildGroupsTask14doInBackgroundFS0_FT_T_U_FTGSqCSo7EKEvent_GVSs20UnsafeMutablePointerV10ObjectiveC8ObjCBool__T_ (WmBuildGroupsTask.swift)
18 MyApp 0x000d96b8 reabstraction thunk helper from #callee_owned (#owned Swift.ImplicitlyUnwrappedOptional<ObjectiveC.EKEvent>, #unowned Swift.UnsafeMutablePointer<ObjectiveC.ObjCBool>) -> (#unowned ()) to #callee_unowned #objc_block (#unowned Swift.ImplicitlyUnwrappedOptional<ObjectiveC.EKEvent>, #unowned Swift.UnsafeMutablePointer<ObjectiveC.ObjCBool>) -> (#unowned ()) (WmBuildGroupsTask.swift)
19 EventKit 0x29ba72a7 __60-[EKEventStore enumerateEventsMatchingPredicate:usingBlock:]_block_invoke + 130
20 EventKit 0x29bad6af __41-[EKPredicateSearch startWithCompletion:]_block_invoke_2 + 690
21 libdispatch.dylib 0x36ed07bb _dispatch_call_block_and_release + 10
22 libdispatch.dylib 0x36ed9dab _dispatch_root_queue_drain + 866
23 libdispatch.dylib 0x36edacd7 _dispatch_worker_thread3 + 94
24 libsystem_pthread.dylib 0x37031e31 _pthread_wqthread + 668
line 9 a.e. WmBuildGroupsTask.swift:421 points to this row if event.attendees != nil{.
Can anybody spread the light on how to get rid of this crash or at least make code safety from crash?
[EDIT 1]
I tried also:
if event.hasAttendees {
if let attArray:NSArray = event.attendees{ // crashes here
/* ... */
}
}
Interesting that from command line: po event.hasAttendees returns true
when po event.attendees return null. But still crashes
[EDIT 2]
After upgrade to Swift 1.2 get the same crashes (In Crashlytics). Also tried:
if event.hasAttendees {
if let attArray:[EKParticipant] = event.attendees as? [EKParticipant] // crash here
{
/* ... */
}
}
The problematic event(s) refers to calendar like Google and as I pointed above 99.5% the same event works properly and I success to fetch attendees.
I'm not iOS Guru but looks like its internal iOS issue:
libobjc.A.dylib 0x36970d5f objc_exception_throw + 250
9 CoreFoundation 0x29096291 -[__NSSetM addObject:] + 608
10 EventKit 0x29b4eacf -[EKPersistentObject primitiveRelationValueForKey:] + 502
11 Foundation 0x29dc1617 -[NSObject(NSKeyValueCoding) valueForKey:] + 202
12 EventKit 0x29b5afc5 -[EKObjectToManyRelation _loadedItems] + 120
13 EventKit 0x29b5aef3 -[EKObjectToManyRelation _effectiveItems] + 102
14 EventKit 0x29b5ae69 -[EKObjectToManyRelation items] + 20
15 EventKit 0x29b5d179 -[EKCalendarItem attendees] + 36
Thanks,
It seems pretty clear that this is a bug in iOS and so you would need a hack to go around it until they fix it.
If it was Objective C I would've used a try catch block to try to catch the exception, so the app would not crash.
Here's an example of using a try block in Swift, by using an Objective C implementation:

Resources