microsoft / appcenter-sdk-apple

Development repository for the App Center SDK for iOS, macOS and tvOS.
Other
564 stars 224 forks source link

Does the SDK crash here during reporting? #2417

Closed datwelk closed 2 years ago

datwelk commented 2 years ago

Description

I am receiving multiple crash reports where one of the threads is PLCrashReporter registering the crash. This thread is not the crashed thread. The crash reason is SEGV_MAPERR and the crashed thread contains a call stack from CFNetwork (CFURLRequestSetMainDocumentURL), ending at libdispatch in _dispatch_source_set_runloop_timer_4CF.

I have previously reported this crash with Apple (https://developer.apple.com/forums/thread/696764). They replied saying this crash is observed on their end in a large variety of different apps, and they suggested it is a bug on their end.

However, in all the crash logs I gathered, PLCrashReporter shows up in one of the threads, with no application-specific code. This, together with Apple's observation, makes me believe this could be an issue with the AppCenter SDK (more specifically PLCrashReporter line 296).

Repro Steps

The steps to reproduce the issue are unclear.

Details

  1. Which SDK version are you using?
    • e.g. 4.4.3
  2. Which OS version did you experience the issue on?
    • e.g. iOS 15
  3. Which Xcode version did you build the app with?
    • e.g. Xcode 13.3
  4. Which Cocoapods version are you using (run pod --version)?
    • None, we use SPM
  5. What device version did you see this error on? Were you using an emulator or a physical device?
    • Physical, iPad 14,2.
  6. What language are you using?
    • [x] Objective C
    • [x] Swift
  7. What third party libraries are you using? Mapbox
  8. Please enable verbose logging for your app using MSAppCenter.setLogLevel(.verbose) before your call to MSAppCenter.start(...) for Swift, or [MSAppCenter setLogLevel:MSLogLevelVerbose] before [MSAppCenter start: ...] for Objective C and include the logs here: Not possible, since this is a crash log.

Logs: crash_log.txt

DmitriyKirakosyan commented 2 years ago

Hi @datwelk , thank you for reaching out to us! Actually, I believe it is natural that PLCrashReporter is mentioned in your logs as it catches the crash. The crash happened and then the callback mach_exception_callback is fired and it ended up PLCR being visible in you crash log. Do you have this line (296) in ALL the crash logs you gathered?

Can you add some analytics in places of network activity in your app? This could help to gather more info of this issue.

datwelk commented 2 years ago

Hi @DmitriyKirakosyan, thank you for your reply. That makes sense. Indeed, in all crash logs regarding this issue, I see PLCR mentioned with the same line (296).

I managed to gather another log, where the main thread's state is also captured. It seems to be an issue with cookies + multithreading in CFNetwork. Really disappointed in Apple, this crash ruins our application's user experience. I am not sure how to work around the issue. What would be your advice in terms of analytics, can I use the AppCenter SDK to gather additional diagnostics right before the crash occurs?

Thread 30 Crashed:
0   libdispatch.dylib                    0x00000001803eab84 _dispatch_source_set_runloop_timer_4CF + 32
1   CFNetwork                            0x0000000180f16824 CFURLRequestSetMainDocumentURL + 1872
2   CFNetwork                            0x00000001810d15ac _CFNetworkErrorGetLocalizedDescription + 694196
3   CFNetwork                            0x0000000180f17cfc CFURLRequestSetMainDocumentURL + 7208
4   CFNetwork                            0x0000000180f0dc48 CFURLRequestSetURL + 9536
5   libdispatch.dylib                    0x00000001803d3e6c _dispatch_call_block_and_release + 28
6   libdispatch.dylib                    0x00000001803d5a30 _dispatch_client_callout + 16
7   libdispatch.dylib                    0x00000001803dd124 _dispatch_lane_serial_drain + 664
8   libdispatch.dylib                    0x00000001803ddcb4 _dispatch_lane_invoke + 440
9   libdispatch.dylib                    0x00000001803d87ac _dispatch_workloop_stealer_invoke + 340
10  libdispatch.dylib                    0x00000001803def80 _dispatch_workloop_invoke + 1780
11  libdispatch.dylib                    0x00000001803e8500 _dispatch_workloop_worker_thread + 644
12  libsystem_pthread.dylib              0x00000001f06c80bc _pthread_wqthread + 284
13  libsystem_pthread.dylib              0x00000001f06c7e5c start_wqthread + 4

Thread 0:
0   CoreFoundation                       0x00000001806f1a7c CFRelease + 60
1   CoreFoundation                       0x0000000180719670 __CFBasicHashDrain + 308
2   CoreFoundation                       0x00000001806e902c _CFRelease + 228
3   CFNetwork                            0x0000000180f5b33c CFHTTPCookieStorageCreateFromFile + 4612
4   CoreFoundation                       0x00000001806e902c _CFRelease + 228
5   CFNetwork                            0x0000000180f0d20c CFURLRequestSetURL + 6916
6   CoreFoundation                       0x00000001806e902c _CFRelease + 228
7   CFNetwork                            0x0000000180efb0a0 CFURLRequestSetHTTPRequestBody + 16256
8   libobjc.A.dylib                      0x000000019945a380 object_cxxDestructFromClass(objc_object*, objc_class*) + 112
9   libobjc.A.dylib                      0x00000001994571b4 objc_destructInstance + 76
10  libobjc.A.dylib                      0x0000000199460a00 _objc_rootDealloc + 76
11  CFNetwork                            0x0000000180ef6af0 0x180ef4000 + 10992
12  CFNetwork                            0x0000000180efbdd4 CFURLRequestSetHTTPRequestBody + 19636
13  CFNetwork                            0x0000000180f40b24 CFURLCacheRemoveAllCachedResponses + 10948
14  libobjc.A.dylib                      0x000000019945a380 object_cxxDestructFromClass(objc_object*, objc_class*) + 112
15  libobjc.A.dylib                      0x00000001994571b4 objc_destructInstance + 76
16  libobjc.A.dylib                      0x0000000199460a00 _objc_rootDealloc + 76
17  CoreFoundation                       0x00000001806e3158 __RELEASE_OBJECTS_IN_THE_ARRAY__ + 112
18  CoreFoundation                       0x00000001806f6e6c -[__NSArrayM dealloc] + 272
19  CFNetwork                            0x0000000180f05718 CFURLCacheSetMemoryCapacity + 3628
20  libobjc.A.dylib                      0x000000019945a380 object_cxxDestructFromClass(objc_object*, objc_class*) + 112
21  libobjc.A.dylib                      0x00000001994571b4 objc_destructInstance + 76
22  libobjc.A.dylib                      0x0000000199460a00 _objc_rootDealloc + 76
23  CFNetwork                            0x0000000180f0bce8 CFURLRequestSetURL + 1504
24  CFNetwork                            0x0000000180f06210 CFURLCacheSetMemoryCapacity + 6436
25  libobjc.A.dylib                      0x0000000199459b14 AutoreleasePoolPage::releaseUntil(objc_object**) + 192
26  libobjc.A.dylib                      0x0000000199455e54 objc_autoreleasePoolPop + 208
27  FrontBoardServices                   0x0000000192959310 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 244
28  FrontBoardServices                   0x000000019295f824 __94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke + 392
29  libdispatch.dylib                    0x00000001803d5a30 _dispatch_client_callout + 16
30  libdispatch.dylib                    0x00000001803d94e0 _dispatch_block_invoke_direct + 260
31  FrontBoardServices                   0x000000019295ac70 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 44
32  FrontBoardServices                   0x000000019295a040 -[FBSSerialQueue _targetQueue_performNextIfPossible] + 216
33  FrontBoardServices                   0x000000019295e700 -[FBSSerialQueue _performNextFromRunLoopSource] + 24
34  CoreFoundation                       0x0000000180790414 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
35  CoreFoundation                       0x00000001807a11a0 __CFRunLoopDoSource0 + 204
36  CoreFoundation                       0x00000001806da694 __CFRunLoopDoSources0 + 264
37  CoreFoundation                       0x00000001806e005c __CFRunLoopRun + 824
38  CoreFoundation                       0x00000001806f3bc8 CFRunLoopRunSpecific + 596
39  GraphicsServices                     0x000000019c827374 GSEventRunModal + 160
40  UIKitCore                            0x0000000183063648 -[UIApplication _run] + 1096
41  UIKitCore                            0x0000000182de4d90 UIApplicationMain + 360
DmitriyKirakosyan commented 2 years ago

What would be your advice in terms of analytics, can I use the AppCenter SDK to gather additional diagnostics right before the crash occurs?

Yes, that is what I meant. Just add Analytics.trackEvent in places you think could be involved. Then you can check what events where called before the crash.

DmitriyKirakosyan commented 2 years ago

I'm closing this issue as not related to PLCrashReporter, but feel free to reopen if you find some evidences if PLCR is responsible for the crash. Please share with us anything you would able to find during the investigation and gathering analytics.