adobe / aepsdk-analytics-ios

Adobe Experience Platform Analytics SDK in Swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

specialized static AnalyticsHelper.getApplicationState()

akashyapcastco opened this issue · comments

Expected Behaviour

App should not crash and AnalyticsHelper.getApplicationState() should return current applicationState.

Actual Behaviour

App is crashing while sending analytics context in AnalyticsHelper.getApplicationState() line no- 25

Reproduce Scenario (including but not limited to)

It is a random crash, We don't have exact steps to reproduce this crash.

Platform and Version

iOS - All versions,

Sample Code that illustrates the problem

class AnalyticsHelper {
/// The app’s current state, or that of its most active scene.
/// - Returns: The app's current state
@available(iOSApplicationExtension, unavailable)
@available(tvOSApplicationExtension, unavailable)
static func getApplicationState() -> UIApplication.State? {
var ret: UIApplication.State?
if Thread.isMainThread {
ret = UIApplication.shared.applicationState
} else {
DispatchQueue.main.sync {
ret = UIApplication.shared.applicationState
}
}
return ret
}
}

Logs taken while reproducing problem

Analytics
0 libsystem_kernel.dylib 0x1ad0 __ulock_wait + 8
1 libdispatch.dylib 0x34128 _dlock_wait + 52
2 libdispatch.dylib 0x33f10 _dispatch_thread_event_wait_slow$VARIANT$armv81 + 52
3 libdispatch.dylib 0x46cfc DISPATCH_WAIT_FOR_QUEUE + 340
4 libdispatch.dylib 0x468fc dispatch_sync_f_slow + 140
5 AppName 0x717028 specialized static AnalyticsHelper.getApplicationState() + 25 (AnalyticsHelper.swift:25)
6 AppName 0x712ec4 vtable thunk for AnalyticsBase.getApplicationStateVar() dispatching to Analytics.getApplicationStateVar() + 4370689732 (:4370689732)
7 AppName 0x711e58 AnalyticsBase.processAnalyticsVars(trackData:timestamp:) + 623 (Analytics.swift:623)
8 AppName 0x710d58 AnalyticsBase.track(eventData:timeStampInSeconds:isBackdatedHit:eventUniqueIdentifier:) + 531 (Analytics.swift:531)
9 AppName 0x70e070 AnalyticsBase.handleTrackRequest(event:eventData:) + 229 (Analytics.swift:229)
10 AppName 0x70de04 AnalyticsBase.handleGenericTrackEvent(
:) + 212 (Analytics.swift:212)
11 AppName 0x713408 closure #1 in AnalyticsBase.handleIncomingEvent(event:) + 171 (Analytics.swift:171)
12 AppName 0x722a38 thunk for @escaping @callee_guaranteed () -> () + 4370754104 (:4370754104)
13 libdispatch.dylib 0x637a8 _dispatch_call_block_and_release + 24
14 libdispatch.dylib 0x64780 _dispatch_client_callout + 16
15 libdispatch.dylib 0x3f6fc _dispatch_lane_serial_drain$VARIANT$armv81 + 600
16 libdispatch.dylib 0x401b0 _dispatch_lane_invoke$VARIANT$armv81 + 380
17 libdispatch.dylib 0x49f14 _dispatch_workloop_worker_thread + 608
18 libsystem_pthread.dylib 0x1bd0 _pthread_wqthread + 284
19 libsystem_pthread.dylib 0x1720 start_wqthread + 8

Hi @akashyapcastco ,

Thank you for reporting this issue. Can you provide us with a little more information to help us debug?

  1. Which version of the Analytics SDK and Mobile Core SDK are you using?
  2. Can you provide the full crash logs with all threads, and any reported crash message?
  3. Are you seeing the crash on any specific platform, (i.e. iPhone, iPad) and which versions?
  4. Is the crash happening when the app is in the foreground or background?

Thank you,
Kevin

Hi @kevinlind Thank you for your response. please find the requested details below:

Currently we are using v3.2.0 for my recent release. but looks like Analytics SDK has the newer version v4.0.0.

Platform: iPhone
Device: iPhone 11, iPhone SE
OS: iOS 14.3.0

crash logs:
`

Crashlytics - Stack trace

Application: com..

Platform: apple

Version: 7.7.2 (13034)

Issue: 3fd59ace4b6eff1266f1a478dd332cd0

Session: 08312be1734d4f558d80bbaa65eeb797_DNE_0_v2

Date: Thu Jan 04 2024 09:23:15 GMT-0800 (Pacific Standard Time)

Thread
0 libsystem_kernel.dylib 0x29184 __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x3850 _pthread_wqthread + 352
2 libsystem_pthread.dylib 0xa75c start_wqthread + 8

Analytics
0 libsystem_kernel.dylib 0x28f5c __ulock_wait + 8
1 libdispatch.dylib 0x4794 _dlock_wait + 56
2 libdispatch.dylib 0x4528 _dispatch_thread_event_wait_slow + 56
3 libdispatch.dylib 0x12708 DISPATCH_WAIT_FOR_QUEUE + 352
4 libdispatch.dylib 0x122b0 dispatch_sync_f_slow + 148
5 appname 0x7c3cb4 specialized static AnalyticsHelper.getApplicationState() + 25 (AnalyticsHelper.swift:25)
6 appname 0x7bf75c vtable thunk for AnalyticsBase.getApplicationStateVar() dispatching to Analytics.getApplicationStateVar() + 4371380060 (:4371380060)
7 appname 0x7be6f8 AnalyticsBase.processAnalyticsVars(trackData:timestamp:) + 623 (Analytics.swift:623)
8 appname 0x7bd658 AnalyticsBase.track(eventData:timeStampInSeconds:isBackdatedHit:eventUniqueIdentifier:) + 531 (Analytics.swift:531)
9 appname 0x7ba970 AnalyticsBase.handleTrackRequest(event:eventData:) + 229 (Analytics.swift:229)
10 appname 0x7ba704 AnalyticsBase.handleGenericTrackEvent(
:) + 212 (Analytics.swift:212)
11 appname 0x7bfca8 closure #1 in AnalyticsBase.handleIncomingEvent(event:) + 171 (Analytics.swift:171)
12 appname 0x7cf5d4 thunk for @escaping @callee_guaranteed () -> () + 4371445204 (:4371445204)
13 libdispatch.dylib 0x224c _dispatch_call_block_and_release + 32
14 libdispatch.dylib 0x3db0 _dispatch_client_callout + 20
15 libdispatch.dylib 0xb10c _dispatch_lane_serial_drain + 580
16 libdispatch.dylib 0xbc5c _dispatch_lane_invoke + 408
17 libdispatch.dylib 0x15d78 _dispatch_workloop_worker_thread + 708
18 libsystem_pthread.dylib 0x3804 _pthread_wqthread + 276
19 libsystem_pthread.dylib 0xa75c start_wqthread + 8

com.apple.uikit.eventfetch-thread
0 libsystem_kernel.dylib 0x42d0 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x3660 mach_msg + 76
2 CoreFoundation 0xa0c30 __CFRunLoopServiceMachPort + 380
3 CoreFoundation 0x9ac14 __CFRunLoopRun + 1216
4 CoreFoundation 0x9a21c CFRunLoopRunSpecific + 600
5 Foundation 0x8df0 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 232
6 Foundation 0x8cbc -[NSRunLoop(NSRunLoop) runUntilDate:] + 92
7 UIKitCore 0xc7cd48 -[UIEventFetcher threadMain] + 516
8 Foundation 0x17aa34 NSThread__start + 864
9 libsystem_pthread.dylib 0x1b40 _pthread_start + 320
10 libsystem_pthread.dylib 0xa768 thread_start + 8

Thread
0 libsystem_kernel.dylib 0x29184 __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x3850 _pthread_wqthread + 352
2 libsystem_pthread.dylib 0xa75c start_wqthread + 8

Thread
0 libsystem_kernel.dylib 0x29184 __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x3850 _pthread_wqthread + 352
2 libsystem_pthread.dylib 0xa75c start_wqthread + 8

com.google.firebase.crashlytics.MachExceptionServer
0 libsystem_kernel.dylib 0x42d0 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x3660 mach_msg + 76
2 app 0x78d8f8 FIRCLSMachExceptionServer + 192 (FIRCLSMachException.c:192)
3 libsystem_pthread.dylib 0x1b40 _pthread_start + 320
4 libsystem_pthread.dylib 0xa768 thread_start + 8

Thread
0 libsystem_kernel.dylib 0x42d0 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x3660 mach_msg + 76
2 appname 0x932a14 exception_server_thread + 684 (PLCrashMachExceptionServer.m:684)
3 libsystem_pthread.dylib 0x1b40 _pthread_start + 320
4 libsystem_pthread.dylib 0xa768 thread_start + 8

Thread
0 libsystem_kernel.dylib 0x29184 __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x3850 _pthread_wqthread + 352
2 libsystem_pthread.dylib 0xa75c start_wqthread + 8

JavaScriptCore bmalloc scavenger
0 libsystem_kernel.dylib 0x281ac __psynch_cvwait + 8
1 libsystem_pthread.dylib 0x5458 _pthread_cond_wait + 1192
2 libc++.1.dylib 0xd328 std::__1::condition_variable::wait(std::__1::unique_lockstd::__1::mutex&) + 28
3 JavaScriptCore 0xecb400 void std::__1::condition_variable_any::wait<std::__1::unique_lockbmalloc::Mutex >(std::__1::unique_lockbmalloc::Mutex&) + 108
4 JavaScriptCore 0xecfacc bmalloc::Scavenger::threadRunLoop() + 208
5 JavaScriptCore 0xecf6d8 bmalloc::Scavenger::Scavenger(std::__1::scoped_lockbmalloc::Mutex const&) + 14
6 JavaScriptCore 0xed0bf0 std::__1::__thread_specific_ptrstd::__1::__thread_struct::set_pointer(std::__1::__thread_struct*) + 46
7 libsystem_pthread.dylib 0x1b40 _pthread_start + 320
8 libsystem_pthread.dylib 0xa768 thread_start + 8

com.apple.NSURLConnectionLoader
0 libsystem_kernel.dylib 0x42d0 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x3660 mach_msg + 76
2 CoreFoundation 0xa0c30 __CFRunLoopServiceMachPort + 380
3 CoreFoundation 0x9ac14 __CFRunLoopRun + 1216
4 CoreFoundation 0x9a21c CFRunLoopRunSpecific + 600
5 CFNetwork 0x24c2c0 _CFURLStorageSessionCopyCache + 64452
6 Foundation 0x17aa34 NSThread__start + 864
7 libsystem_pthread.dylib 0x1b40 _pthread_start + 320
8 libsystem_pthread.dylib 0xa768 thread_start + 8

com.mobile-messaging.queue.serial.user-session
0 libsystem_kernel.dylib 0x28f5c __ulock_wait + 8
1 libdispatch.dylib 0x4794 _dlock_wait + 56
2 libdispatch.dylib 0x4528 _dispatch_thread_event_wait_slow + 56
3 libdispatch.dylib 0x12708 DISPATCH_WAIT_FOR_QUEUE + 352
4 libdispatch.dylib 0x122b0 dispatch_sync_f_slow + 148
5 MobileMessaging 0x985a4 $s15MobileMessaging11getFromMain6getterxxyXE_tlFSo18UIApplicationStateV_Tg504$s15a11Messaging25e8Threadedg14C16applicationH17So0eG0VvgAFyXEfU_AA0ekG0CTf1c_nTf4g_n + 468
6 MobileMessaging 0xc91c8 $s15MobileMessaging25MainThreadedUIApplicationCAA13MMApplicationA2aDP26applicationIconBadgeNumberSivgTWTm + 32
7 MobileMessaging 0x150688 $s15MobileMessaging18UserSessionServiceC16handleTimerEvent33_2F82632374A63E9113670FF10A8E0397LLyyF + 284
8 MobileMessaging 0x151368 $s15MobileMessaging18UserSessionServiceC10setupTimer33_2F82632374A63E9113670FF10A8E0397LLyyFyycACcfu_yycfu0_TA + 20
9 MobileMessaging 0x103aac $s15MobileMessaging14RepeatingTimerC5timer33_50D4B66D5B15AA81BC5CF715265F141ELLSo019OS_dispatch_source_E0_pvgSoAF_pyXEfU_yycfU
+ 92
10 MobileMessaging 0xed83c $sIeg_IeyB_TR + 28
11 libdispatch.dylib 0x3db0 _dispatch_client_callout + 20
12 libdispatch.dylib 0x712c _dispatch_continuation_pop + 416
13 libdispatch.dylib 0x18c08 _dispatch_source_invoke + 1260
14 libdispatch.dylib 0xafd8 _dispatch_lane_serial_drain + 272
15 libdispatch.dylib 0xbc5c _dispatch_lane_invoke + 408
16 libdispatch.dylib 0x15d78 _dispatch_workloop_worker_thread + 708
17 libsystem_pthread.dylib 0x3804 _pthread_wqthread + 276
18 libsystem_pthread.dylib 0xa75c start_wqthread + 8

NSManagedObjectContext 0x2835ede10: background
0 libsystem_kernel.dylib 0x28f5c __ulock_wait + 8
1 libdispatch.dylib 0x4794 _dlock_wait + 56
2 libdispatch.dylib 0x4528 _dispatch_thread_event_wait_slow + 56
3 libdispatch.dylib 0x12708 DISPATCH_WAIT_FOR_QUEUE + 352
4 libdispatch.dylib 0x122b0 _dispatch_sync_f_slow + 148
5 CoreData 0x13b88c perform + 208
6 CoreData 0xf820 -[NSManagedObjectContext(NestedContextSupport) executeRequest:withContext:error:] + 228
7 CoreData 0xb1f8 -[NSManagedObjectContext executeFetchRequest:error:] + 824
8 libswiftCoreData.dylib 0x3528 NSManagedObjectContext.fetch(
:) + 68
9 appname 0x5e0660 specialized CoreDataRepository.get(predicate:sortDescriptors:type:context:) + 50 (CoreDataRepository.swift:50)
10 appname 0x5e052c protocol witness for CoreDataRepositoryProtocol.get(predicate:sortDescriptors:type:context:) in conformance CoreDataRepository + 4369417516 (:4369417516)
11 appname 0x58b214 closure #1 in AccountRemoteDataSource.getDMCDetails() + 172 (AccountRemoteDataSource.swift:172)
12 appname 0x5e33bc closure #1 in NSManagedObjectContext.performAndWait(
:) + 83 (NSManagedObjectContext+Extension.swift:83)
13 appname 0x5e30b0 partial apply for thunk for @callee_guaranteed () -> () + 4369428656 (:4369428656)
14 appname 0x5e2c78 thunk for @escaping @callee_guaranteed () -> () + 4369427576 (:4369427576)
15 CoreData 0x1400f8 developerSubmittedBlockToNSManagedObjectContextPerform + 164
16 libdispatch.dylib 0x3db0 _dispatch_client_callout + 20
17 libdispatch.dylib 0x12428 dispatch_lane_barrier_sync_invoke_and_complete + 60
18 CoreData 0xa270 -[NSManagedObjectContext performBlockAndWait:] + 268
19 appname 0x5e3294 NSManagedObjectContext.performAndWait
(:) + 82 (NSManagedObjectContext+Extension.swift:82)
20 appname 0x58ae30 AccountRemoteDataSource.checkDMCAndUpdateIfNecessary() + 171 (AccountRemoteDataSource.swift:171)
21 libswift_Concurrency.dylib 0x2de64 swift::runJobInEstablishedExecutorContext(swift::Job*) + 152
22 libswift_Concurrency.dylib 0x2e870 swift_job_runImpl(swift::Job*, swift::ExecutorRef) + 80
23 libdispatch.dylib 0x3db0 _dispatch_client_callout + 20
24 libdispatch.dylib 0x712c _dispatch_continuation_pop + 416
25 libdispatch.dylib 0x6854 _dispatch_async_redirect_invoke + 592
26 libdispatch.dylib 0x1493c _dispatch_root_queue_drain + 356
27 libdispatch.dylib 0x15120 _dispatch_worker_thread2 + 116
28 libsystem_pthread.dylib 0x37c8 _pthread_wqthread + 216
29 libsystem_pthread.dylib 0xa75c start_wqthread + 8
`

Thanks,
Ramesh

Hi,

I haven't been able to reproduce this crash locally yet. I'm hoping you could give me some more information to help with my investigation. From the stack trace you've provided it is still not clear which thread is crashing or why. However, the stack trace does show there are at least two threads, "Analytics" and "com.mobile-messaging.queue.serial.user-session", which dispatch a request to to the main thread to get data from UIApplication. My current thinking is there could be a deadlock scenario here between the two SDKs causing the application to stall and crash.

  1. Can you confirm your application is using the mobile-messaging-sdk-ios library, and if so which version are you using?
  2. Do you have the full Apple crash logs including the exception information? This can give clues as to why the application crashed. In particular, if the termination reason code is 0x8badf00d, then the crash is a watchdog termination which can point to a potential deadlock.
  3. Is the crash report stack trace consistent with each crash? Are you seeing the same threads "Analytics", "com.mobile-messaging.queue.serial.user-session", and "NSManagedObjectContext" in each crash report with the same stack trace?
  4. How frequent is the crash occurring and how many customers are affected?

Thank you.

Hi unfortunatly don't seee any additional information from crashlytics. I already posted all the threads which includes crash thread info in my initial question above. please find inline responses to your questions

  1. Can you confirm your application is using the mobile-messaging-sdk-ios library, and if so which version are you using? - Not sure how it's related to this but we are using 10.23.1
  2. Do you have the full Apple crash logs including the exception information? This can give clues as to why the application crashed. In particular, if the termination reason code is 0x8badf00d, then the crash is a watchdog termination which can point to a potential deadlock. - Already provided above, not found anything else in crashlytics
  3. Is the crash report stack trace consistent with each crash? Are you seeing the same threads "Analytics", "com.mobile-messaging.queue.serial.user-session", and "NSManagedObjectContext" in each crash report with the same stack trace?
  4. How frequent is the crash occurring and how many customers are affected? - it has more occurrences, we rolled out just 1% but noticed more than 76 crashes.