twilio / conversations-ios

SPM releases
https://www.twilio.com/docs/conversations/ios/changelog
10 stars 5 forks source link

[pre-4.0] Crash in TwilioConversationsClient initializeClientWithToken:completion: #45

Closed vidriloco closed 7 months ago

vidriloco commented 9 months ago

Hello folks,

We are dealing with a Twilio crash issue affecting like the 20% of our users when in background mode (at least that's what Crashlytics reports).

The stack trace is the one below:

Crashed: com.apple.root.background-qos
0  libdispatch.dylib              0x8880 dispatch_async + 188
1  libdispatch.dylib              0x8880 dispatch_channel_async + 188
2  TwilioConversationsClient      0x65208 ___ZZZ66-[TwilioConversationsClient initializeClientWithToken:completion:]EUb0_ENK3$_3clENSt3__110shared_ptrIN3rtd9ITMResultEEE_block_invoke + 756
3  libdispatch.dylib              0x2320 _dispatch_call_block_and_release + 32
4  libdispatch.dylib              0x3eac _dispatch_client_callout + 20
5  libdispatch.dylib              0x15a64 _dispatch_root_queue_drain + 684
6  libdispatch.dylib              0x16158 _dispatch_worker_thread2 + 164
7  libsystem_pthread.dylib        0xda0 _pthread_wqthread + 228
8  libsystem_pthread.dylib        0xb7c start_wqthread + 8

As you can see, is not really helpful to identify the underlying cause or to even reproducing it. I've combed the issues that have been reported so far in this repository and see that there are multiple reports, for example this one or this other one. The former conversation conclusion is that a fix was provided for v 2.5.5, but however, in the latter conversation it seems that the issue (or a similar one) persists beyond v 3.0.0.

In the case of my project, we cannot yet upgrade to v 4.0.0 of the SDK. I would like to know guys, if you have some guidelines that you've identified under which this issue might occur, beyond what has been described in the first referenced issue.

And I have already filled a support ticket (ID: 13618253)

Thanks!

berkus commented 8 months ago

Internal tickets: ref:4259

kuchmiyalex commented 7 months ago

I think we're seeing the same, the app submission was even rejected due to a crash on the app launch. Is there anything helpful in this log? Thanks.

Crashlog-2023-12-03-114020.txt

0 libsystem_kernel.dylib 0x1dc4bcc2c kevent_id + 8 1 libdispatch.dylib 0x19cf8fb10 _dispatch_kq_poll + 228 2 libdispatch.dylib 0x19cf904e0 _dispatch_event_loop_wait_for_ownership + 436 3 libdispatch.dylib 0x19cf7c984 DISPATCH_WAIT_FOR_QUEUE + 340 4 libdispatch.dylib 0x19cf7c54c _dispatch_sync_f_slow + 148 5 libswiftDispatch.dylib 0x19e409078 implicit closure #2 in implicit closure #1 in OS_dispatch_queue.asyncAndWait(execute:) + 192 6 libswiftDispatch.dylib 0x19e408fb0 partial apply for implicit closure #2 in implicit closure #1 in OS_dispatch_queue.sync(execute:) + 76 7 libswiftDispatch.dylib 0x19e408e30 OS_dispatch_queue._syncHelper(fn:execute:rescue:) + 396 8 libswiftDispatch.dylib 0x19e408c74 OS_dispatch_queue.asyncAndWait(execute:) + 140 9 libswiftDispatch.dylib 0x19e408be0 OS_dispatchqueue.sync(execute:) + 64 10 TwilioStateMachine 0x1043711dc StateMachine.transition(:) + 460 11 TwilioStateMachine 0x1043749e0 dispatch thunk of StateMachine.transition(:) + 20 12 TwilioTwilsockLib 0x1043af700 specialized StateMachine.safeTransition(:) + 204 13 TwilioTwilsockLib 0x1043b1614 Twilsock.connect() + 148 14 TwilioTwilsockLib 0x1043b90a0 protocol witness for TwilsockProtocol.connect() in conformance Twilsock + 20 15 TwilioTwilsockLib 0x1043d6428 @objc TwilsockObjCInterface.connect() + 136 16 TwilioConversationsClient 0x103c849c4 rtd::twilsock::Twilsock::connect() + 92 17 TwilioConversationsClient 0x103c84efc rtd::twilsock::Twilsock::reconnect() + 76 18 TwilioConversationsClient 0x103d6c63c -[TwilioConversationsClient reconnectTwilsock] + 144 19 TwilioConversationsClient 0x103d6c7a8 -[TwilioConversationsClient applicationWillEnterForeground:] + 144 20 CoreFoundation 0x194fdf4c8 CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER_ + 148 21 CoreFoundation 0x194fdee90 CFXRegistrationPost_block_invoke + 88 22 CoreFoundation 0x194fdedd8 _CFXRegistrationPost + 440 23 CoreFoundation 0x194fde328 _CFXNotificationPost + 724 24 Foundation 0x193f7a864 -[NSNotificationCenter postNotificationName:object:userInfo:] + 92 25 UIKitCore 0x19736154c -[UIApplication _sendWillEnterForegroundCallbacks] + 212 26 UIKitCore 0x19735fccc 101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]_block_invoke_2 + 1272 27 UIKitCore 0x19735f798 _UIScenePerformActionsWithLifecycleActionMask + 112 28 UIKitCore 0x1973e6e74 101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]_block_invoke + 216 29 UIKitCore 0x19730e778 -[_UISceneLifecycleMultiplexer _performBlock:withApplicationOfDeactivationReasons:fromReasons:] + 220 30 UIKitCore 0x19730d1f0 -[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:] + 608 31 UIKitCore 0x19730cb58 -[_UISceneLifecycleMultiplexer uiScene:transitionedFromState:withTransitionContext:] + 248 32 UIKitCore 0x19730ca28 186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke + 148 33 UIKitCore 0x19730c930 +[BSAnimationSettings(UIKit) tryAnimatingWithSettings:fromCurrentState:actions:completion:] + 736 34 UIKitCore 0x19730c1b8 _UISceneSettingsDiffActionPerformChangesWithTransitionContextAndCompletion + 224 35 UIKitCore 0x19730be68 -[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:] + 316 36 UIKitCore 0x19768f620 __64-[UIScene scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke.225 + 612 37 UIKitCore 0x19730afec -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 216 38 UIKitCore 0x19730ae5c -[UIScene scene:didUpdateWithDiff:transitionContext:completion:] + 244 39 UIKitCore 0x19730ac9c -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:] + 336 40 FrontBoardServices 0x1ad24e5b4 -[FBSScene updater:didUpdateSettings:withDiff:transitionContext:completion:] + 660 41 FrontBoardServices 0x1ad24e300 94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke_2 + 152 42 FrontBoardServices 0x1ad24e19c -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 168 43 FrontBoardServices 0x1ad24e0b8 94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke + 344 44 libdispatch.dylib 0x19cf6d300 _dispatch_client_callout + 20 45 libdispatch.dylib 0x19cf70d48 _dispatch_block_invoke_direct + 284 46 FrontBoardServices 0x1ad24a520 FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 52 47 FrontBoardServices 0x1ad24a4a0 -[FBSMainRunLoopSerialQueue _targetQueue_performNextIfPossible] + 240 48 FrontBoardServices 0x1ad24a378 -[FBSMainRunLoopSerialQueue _performNextFromRunLoopSource] + 28 49 CoreFoundation 0x194fe731c CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 28 50 CoreFoundation 0x194fe6598 CFRunLoopDoSource0 + 176 51 CoreFoundation 0x194fe4d4c CFRunLoopDoSources0 + 244 52 CoreFoundation 0x194fe3a88 CFRunLoopRun + 828 53 CoreFoundation 0x194fe3668 CFRunLoopRunSpecific + 608 54 GraphicsServices 0x1d83ae5ec GSEventRunModal + 164 55 UIKitCore 0x1974002b4 -[UIApplication _run] + 888 56 UIKitCore 0x1973ff8f0 UIApplicationMain + 340 57 AppNameHere 0x10099ed94 0x100774000 + 2272660 58 dyld 0x1b7a36dcc start + 2240

vidriloco commented 7 months ago

Hey @berkus. Is there anything that we can do to address the intermittent crashes? Any lead or suggestion is very well welcomed. Thanks guys for your work on this framework!

berkus commented 7 months ago

This part seems like a deadlock in the state machine serialization, a fix for this should now be available in 4.0.3

1 libdispatch.dylib 0x19cf8fb10 _dispatch_kq_poll + 228
2 libdispatch.dylib 0x19cf904e0 dispatch_event_loop_wait_for_ownership + 436
3 libdispatch.dylib 0x19cf7c984 DISPATCH_WAIT_FOR_QUEUE + 340
4 libdispatch.dylib 0x19cf7c54c dispatch_sync_f_slow + 148
5 libswiftDispatch.dylib 0x19e409078 implicit closure https://github.com/twilio/conversations-ios/issues/2 in implicit closure https://github.com/twilio/conversations-ios/issues/1 in OS_dispatch_queue.asyncAndWait(execute:) + 192
6 libswiftDispatch.dylib 0x19e408fb0 partial apply for implicit closure https://github.com/twilio/conversations-ios/issues/2 in implicit closure https://github.com/twilio/conversations-ios/issues/1 in OS_dispatch_queue.sync(execute:) + 76
7 libswiftDispatch.dylib 0x19e408e30 OS_dispatch_queue.syncHelper(fn:execute:rescue:) + 396
8 libswiftDispatch.dylib 0x19e408c74 OS_dispatch_queue.asyncAndWait(execute:) + 140
9 libswiftDispatch.dylib 0x19e408be0 OS_dispatch_queue.sync(execute:) + 64
10 TwilioStateMachine 0x1043711dc StateMachine.transition(:) + 460
11 TwilioStateMachine 0x1043749e0 dispatch thunk of StateMachine.transition(:) + 20
12 TwilioTwilsockLib 0x1043af700 specialized StateMachine.safeTransition(:) + 204
13 TwilioTwilsockLib 0x1043b1614 Twilsock.connect() + 148
14 TwilioTwilsockLib 0x1043b90a0 protocol witness for TwilsockProtocol.connect() in conformance Twilsock + 20
15 TwilioTwilsockLib 0x1043d6428 @objc TwilsockObjCInterface.connect() + 136
16 TwilioConversationsClient 0x103c849c4 rtd::twilsock::Twilsock::connect() + 92
17 TwilioConversationsClient 0x103c84efc rtd::twilsock::Twilsock::reconnect() + 76
18 TwilioConversationsClient 0x103d6c63c -[TwilioConversationsClient reconnectTwilsock] + 144
19 TwilioConversationsClient 0x103d6c7a8 -[TwilioConversationsClient applicationWillEnterForeground:] + 144
vidriloco commented 7 months ago

Thanks @berkus . We have started with migration to the latest version of the SDK.