Appboy / appboy-ios-sdk

Public repo for the Braze iOS SDK
https://www.braze.com
Other
165 stars 142 forks source link

Avoid access to CoreTelephony from main queue #302

Closed vmagaziy closed 2 years ago

vmagaziy commented 3 years ago

Report

Describe your environment.

Info Value
Platform Name iOS
Platform Version 14.5
SDK Version 4.0.2
Integration Method SPM
Xcode Version Xcode 12.5
Computer Processor Intel-based
Repro rate All the time

What did you do?

Bringing the app which uses the SDK to the foreground

What did you expect to happen?

What happened instead?

The app stalls for a while as the SDK is accessing CoreTelephony, which involves XPC and thus these calls are taking time making the app irresponsive

Steps to reproduce

See above

Code Snippet

n/a

Are you doing any feature customizations that may relate to the issue? Can you share the code snippet?

n/a

Project that demonstrates the issue

Any project using the SDK will experience this:

* * thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
    frame #0: 0x00007fff20060e4b libxpc.dylib`_xpc_serializer_clear_sent_descriptors + 32
    frame #1: 0x00007fff2006616d libxpc.dylib`_xpc_pipe_mach_msg + 167
    frame #2: 0x00007fff20065c33 libxpc.dylib`_xpc_send_serializer + 74
    frame #3: 0x00007fff20065a94 libxpc.dylib`_xpc_pipe_simpleroutine + 82
    frame #4: 0x00007fff20065d47 libxpc.dylib`xpc_pipe_simpleroutine + 42
    frame #5: 0x00007fff2003a1fe libsystem_trace.dylib`___os_activity_stream_reflect_block_invoke_3 + 29
    frame #6: 0x00000001081a274e libdispatch.dylib`_dispatch_client_callout + 8
    frame #7: 0x00000001081a5656 libdispatch.dylib`_dispatch_block_invoke_direct + 295
    frame #8: 0x00000001081a5524 libdispatch.dylib`dispatch_block_perform + 124
    frame #9: 0x00007fff20039c01 libsystem_trace.dylib`_os_activity_stream_reflect + 646
    frame #10: 0x00007fff200454aa libsystem_trace.dylib`_os_log_impl_stream + 607
    frame #11: 0x00007fff20044e4b libsystem_trace.dylib`_os_log_impl_flatten_and_send + 8114
    frame #12: 0x00007fff20042e8a libsystem_trace.dylib`_os_log + 158
    frame #13: 0x00007fff20048be4 libsystem_trace.dylib`_os_log_error_impl + 21
    frame #14: 0x00007fff24fc14fe CoreTelephony`invocation function for block in -[CoreTelephonyClientMux synchronousProxyWithErrorHandler:]::$_4::operator()() const + 63
    frame #15: 0x00007fff24f5c113 CoreTelephony`invocation function for block in -[CoreTelephonyClientMux synchronousProxyWithErrorHandler:]::$_4::operator()() const + 96
    frame #16: 0x00007fff2092b01e Foundation`__NSXPCCONNECTION_IS_CALLING_OUT_TO_ERROR_BLOCK__ + 7
    frame #17: 0x00007fff2092f511 Foundation`__88-[NSXPCConnection _sendInvocation:orArguments:count:methodSignature:selector:withProxy:]_block_invoke_3 + 860
    frame #18: 0x00007fff2092ec41 Foundation`-[NSXPCConnection _sendInvocation:orArguments:count:methodSignature:selector:withProxy:] + 3190
    frame #19: 0x00007fff2092dfbc Foundation`-[NSXPCConnection _sendInvocation:withProxy:] + 94
    frame #20: 0x00007fff204271fa CoreFoundation`___forwarding___ + 730
    frame #21: 0x00007fff204297a8 CoreFoundation`_CF_forwarding_prep_0 + 120
    frame #22: 0x00007fff24f60ec6 CoreTelephony`-[CoreTelephonyClient getDescriptorsForDomain:error:] + 277
    frame #23: 0x00007fff24f522f4 CoreTelephony`-[CTTelephonyNetworkInfo descriptors] + 71
    frame #24: 0x00007fff24f5314c CoreTelephony`-[CTTelephonyNetworkInfo queryCTSignalStrength] + 57
    frame #25: 0x00007fff24f51279 CoreTelephony`-[CTTelephonyNetworkInfo initWithClient:] + 1173
    frame #26: 0x00007fff24f50d94 CoreTelephony`-[CTTelephonyNetworkInfo init] + 84
    frame #27: 0x000000010151ca5f SvD`__47-[ABKPersistentData deviceCarrierForAppSession]_block_invoke(.block_descriptor=0x000000010161f1e8) at ABKPersistentData.m:688:43
    frame #28: 0x00000001081a274e libdispatch.dylib`_dispatch_client_callout + 8
    frame #29: 0x00000001081a3c9b libdispatch.dylib`_dispatch_once_callout + 66
    frame #30: 0x000000010151ca10 SvD`-[ABKPersistentData deviceCarrierForAppSession] [inlined] _dispatch_once(predicate=0x00000001016a4d70, block=0x000000010151ca30) at once.h:84:3
    frame #31: 0x000000010151c9f9 SvD`-[ABKPersistentData deviceCarrierForAppSession](self=0x0000600001bf4840, _cmd="deviceCarrierForAppSession") at ABKPersistentData.m:686
    frame #32: 0x0000000101545cfa SvD`-[ABKDevice getDeviceCarrier](self=0x0000600000592220, _cmd="getDeviceCarrier") at ABKDevice.m:299:12
    frame #33: 0x0000000101543855 SvD`-[ABKDevice init](self=0x0000600000592220, _cmd="init") at ABKDevice.m:39:17
  * frame #34: 0x0000000101543c2f SvD`+[ABKDevice device](self=ABKDevice, _cmd="device") at ABKDevice.m:76:10
    frame #35: 0x000000010151a267 SvD`-[ABKPersistentData deviceToSendToServer](self=0x0000600001bf4840, _cmd="deviceToSendToServer") at ABKPersistentData.m:376:23
    frame #36: 0x000000010155ccd6 SvD`-[ABKDataServerRequest populateFromUserData:](self=0x00006000005c0540, _cmd="populateFromUserData:", persistentData=0x0000600001bf4840) at ABKDataServerRequest.m:57:17
    frame #37: 0x000000010158c6b2 SvD`-[ABKRequestDispatcher populatedRequestIsEmpty:](self=0x0000600000dfead0, _cmd="populatedRequestIsEmpty:", request=0x00006000005c0540) at ABKRequestDispatcher.m:265:5
    frame #38: 0x000000010158c2a3 SvD`-[ABKRequestDispatcher consumeNextRequestInQueue](self=0x0000600000dfead0, _cmd="consumeNextRequestInQueue") at ABKRequestDispatcher.m:212:24
    frame #39: 0x000000010158cc64 SvD`-[ABKRequestDispatcher processRequestsRegardlessOfConnection](self=0x0000600000dfead0, _cmd="processRequestsRegardlessOfConnection") at ABKRequestDispatcher.m:340:7
    frame #40: 0x000000010158c98a SvD`-[ABKRequestDispatcher consumeNextRequestInQueueIfWeHaveInternetConnectivity](self=0x0000600000dfead0, _cmd="consumeNextRequestInQueueIfWeHaveInternetConnectivity") at ABKRequestDispatcher.m:302:9
    frame #41: 0x000000010158ca86 SvD`-[ABKRequestDispatcher consumeQueueIfWeHaveInternetConnectivity](self=0x0000600000dfead0, _cmd="consumeQueueIfWeHaveInternetConnectivity") at ABKRequestDispatcher.m:315:5
    frame #42: 0x00000001015696ba SvD`-[ABKManager addRequestToFrontOfQueueAndFlushImmediately:](self=0x0000600003b503c0, _cmd="addRequestToFrontOfQueueAndFlushImmediately:", request=0x00006000005c0540) at ABKManager.m:212:3
    frame #43: 0x000000010156979b SvD`-[ABKManager requestTriggerRefresh](self=0x0000600003b503c0, _cmd="requestTriggerRefresh") at ABKManager.m:220:3
    frame #44: 0x0000000101569079 SvD`-[ABKManager requestRefreshForNewMessagingSession](self=0x0000600003b503c0, _cmd="requestRefreshForNewMessagingSession") at ABKManager.m:162:3
    frame #45: 0x000000010152ad23 SvD`-[Appboy startSession](self=0x0000600001cd66d0, _cmd="startSession") at Appboy.m:571:7
    frame #46: 0x000000010152c58c SvD`__54-[Appboy observeHostApplicationStateForSessionEndTime]_block_invoke(.block_descriptor=0x00006000020796b0, notification=@"UIApplicationWillEnterForegroundNotification") at Appboy.m:726:51
    frame #47: 0x00007fff207e87ec Foundation`-[__NSObserver _doit:] + 287
    frame #48: 0x00007fff20363882 CoreFoundation`__CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
    frame #49: 0x00007fff20363851 CoreFoundation`___CFXRegistrationPost_block_invoke + 49
    frame #50: 0x00007fff20362f81 CoreFoundation`_CFXRegistrationPost + 454
    frame #51: 0x00007fff203628ef CoreFoundation`_CFXNotificationPost + 796
    frame #52: 0x00007fff207e9027 Foundation`-[NSNotificationCenter postNotificationName:object:userInfo:] + 59
    frame #53: 0x00007fff246dd35b UIKitCore`-[UIApplication _sendWillEnterForegroundCallbacks] + 185
    frame #54: 0x00007fff23ce7520 UIKitCore`__101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]_block_invoke_2 + 1768
    frame #55: 0x00007fff24272726 UIKitCore`_UIScenePerformActionsWithLifecycleActionMask + 88
    frame #56: 0x00007fff23ce6dad UIKitCore`__101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]_block_invoke + 198
    frame #57: 0x00007fff23ce67bc UIKitCore`-[_UISceneLifecycleMultiplexer _performBlock:withApplicationOfDeactivationReasons:fromReasons:] + 296
    frame #58: 0x00007fff23ce6bda UIKitCore`-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:] + 818
    frame #59: 0x00007fff23ce646f UIKitCore`-[_UISceneLifecycleMultiplexer uiScene:transitionedFromState:withTransitionContext:] + 345
    frame #60: 0x00007fff23cee6d8 UIKitCore`__186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke + 178
    frame #61: 0x00007fff2417c77d UIKitCore`+[BSAnimationSettings(UIKit) tryAnimatingWithSettings:actions:completion:] + 871
    frame #62: 0x00007fff2428f60e UIKitCore`_UISceneSettingsDiffActionPerformChangesWithTransitionContext + 246
    frame #63: 0x00007fff23cee3de UIKitCore`-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:] + 361
    frame #64: 0x00007fff23b117d5 UIKitCore`__64-[UIScene scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke + 797
    frame #65: 0x00007fff23b1024e UIKitCore`-[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 253
    frame #66: 0x00007fff23b1140e UIKitCore`-[UIScene scene:didUpdateWithDiff:transitionContext:completion:] + 208
    frame #67: 0x00007fff241a4f20 UIKitCore`-[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:] + 502
    frame #68: 0x00007fff25a1bc30 FrontBoardServices`-[FBSScene updater:didUpdateSettings:withDiff:transitionContext:completion:] + 530
    frame #69: 0x00007fff25a45418 FrontBoardServices`__94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke_2 + 133
    frame #70: 0x00007fff25a28f12 FrontBoardServices`-[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 209
    frame #71: 0x00007fff25a45360 FrontBoardServices`__94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke + 372
    frame #72: 0x00000001081a274e libdispatch.dylib`_dispatch_client_callout + 8
    frame #73: 0x00000001081a5656 libdispatch.dylib`_dispatch_block_invoke_direct + 295
    frame #74: 0x00007fff25a695d0 FrontBoardServices`__FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 30
    frame #75: 0x00007fff25a692b6 FrontBoardServices`-[FBSSerialQueue _targetQueue_performNextIfPossible] + 433
    frame #76: 0x00007fff25a6977b FrontBoardServices`-[FBSSerialQueue _performNextFromRunLoopSource] + 22
    frame #77: 0x00007fff20390ede CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    frame #78: 0x00007fff20390dd6 CoreFoundation`__CFRunLoopDoSource0 + 180
    frame #79: 0x00007fff20390300 CoreFoundation`__CFRunLoopDoSources0 + 340
    frame #80: 0x00007fff2038a9f7 CoreFoundation`__CFRunLoopRun + 875
    frame #81: 0x00007fff2038a1a7 CoreFoundation`CFRunLoopRunSpecific + 567
    frame #82: 0x00007fff2b874d85 GraphicsServices`GSEventRunModal + 139
    frame #83: 0x00007fff246c14df UIKitCore`-[UIApplication _run] + 912
    frame #84: 0x00007fff246c639c UIKitCore`UIApplicationMain + 101
    frame #85: 0x0000000102d134c9 HermesKit`hermesMain(dependencies=0x0000000101462750 SvD`implicit closure #1 () -> HermesKit.HermesDependencies in SvD at <compiler-generated>) at AppDelegate.swift:372:9
    frame #86: 0x00000001014625c2 SvD`main at main.swift:11:1
    frame #87: 0x00007fff2025abbd libdyld.dylib`start + 1
lowip commented 3 years ago

Hi @vmagaziy!

Thanks for opening this issue. We're tracking it internally and we'll update this thread once this is fixed.

Best,

hokstuff commented 2 years ago

Hi @vmagaziy,

Thanks for filing the information in this thread. I'm updating here because we are planning to address this issue more holistically in our upcoming Swift SDK. Please reference this thread to sign up for our early access program and stay tuned for additional updates regarding the new SDK!

Since there are no immediate follow ups for this issue, I am closing it out. Thank you for understanding!