Closed ottokristine closed 4 years ago
Additional Info: ADAL version: 4.0.4 iOS version: 13.1.3 Xcode Version: 11.1.0
Sorry for a delay.
This issue should be fixed in ADAL 4.0.4. Here's the code for ADAL 4.0.4: https://github.com/AzureAD/microsoft-authentication-library-common-for-objc/blob/5ba624ad4766bf5ab048e1765b0d43ae96c85cd5/IdentityCore/src/oauth2/aad_base/MSIDAADWebviewFactory.m#L68. As the very first thing, it checks that it is running on the main thread.
Are you sure you're using ADAL 4.0.4 and not 4.0.3 (where this was indeed an issue)? I wasn't able to reproduce this using ADAL 4.0.4.
Updated pod to ADAL 4.0.4. The app crashes when a view controller is dismissed. when i run the dismiss instruction inside main thread the crash is resolved.
Hi. Do you use ADAL webview or your custom webview? If you're using your custom webview and calling ADAL APIs to cancel the flow, you should call it from the main thread since it is UIKit API. Thanks.
I am using ADAL webview.
Hi. Do you use ADAL webview or your custom webview? If you're using your custom webview and calling ADAL APIs to cancel the flow, you should call it from the main thread since it is UIKit API. Thanks.
@bonnynotetech Could you please provide the crash stack trace, such that we could take a look?
Date/Time: 2020-02-07T13:30:59Z OS Version: iPhone OS 13.3 Report Version: 104
Exception Type: SIGABRT Exception Codes: #0 at 0x18ae20efc Crashed Thread: 2
Application Specific Information: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'threading violation: expected the main thread'
Last Exception Backtrace: 0 CoreFoundation 0x000000018b03696c exceptionPreprocess + 224 1 libobjc.A.dylib 0x000000018ad4f028 objc_exception_throw + 56 2 CoreFoundation 0x000000018af334fc +[NSException raise:format:arguments:] + 96 3 Foundation 0x000000018b374700 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 128 4 FrontBoardServices 0x00000001902657ec -[FBSSerialQueue assertOnQueue] + 232 5 FrontBoardServices 0x0000000190217460 -[FBSSceneImpl updateClientSettings:withTransitionContext:] + 76 6 FrontBoardServices 0x00000001902176ec -[FBSSceneImpl updateClientSettingsWithTransitionBlock:] + 164 7 FrontBoardServices 0x00000001902175e4 -[FBSSceneImpl updateClientSettingsWithBlock:] + 124 8 UIKitCore 0x000000018ec99120 -[FBSScene(UIApp) updateUIClientSettingsWithBlock:] + 180 9 UIKitCore 0x000000018e8c6700 -[_UISystemAppearanceManager updateScreenEdgesDeferringSystemGestures] + 400 10 UIKitCore 0x000000018eafeb64 70-[UIViewController setNeedsUpdateOfScreenEdgesDeferringSystemGestures]_block_invoke_2 + 120 11 UIKitCore 0x000000018eade67c -[UIViewController _updateSystemAppearanceWithRecursionBlock:action:] + 312 12 UIKitCore 0x000000018eafe780 -[UIViewController _setPresentedStatusBarViewController:] + 244 13 UIKitCore 0x000000018eaf49a4 -[UIViewController _dismissViewControllerWithAnimationController:interactionController:completion:] + 668 14 UIKitCore 0x000000018eaf452c -[UIViewController _dismissViewControllerWithTransition:from:completion:] + 624 15 UIKitCore 0x000000018eaf3cb8 -[UIViewController dismissViewControllerWithTransition:completion:] + 1232 16 UIKitCore 0x000000018eaf36dc -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 524 17 UIKitCore 0x000000018eaf5f5c -[UIViewController dismissViewControllerAnimated:completion:] + 144 18 UIKitCore 0x000000018ea8229c -[UIPopoverController dismissPopoverAnimated:] + 392 19 Formulary 0x0000000104609930 -[FLLoginVC dismissPopover] + 92 20 Formulary 0x000000010460a074 29-[FLLoginVC SSOLoginPressed:]_block_invoke_2 + 396 21 Formulary 0x0000000104662d14 30-[FLNewPadContainer getToken:]_block_invoke + 584 22 Formulary 0x0000000104683df4 70-[ADAuthenticationRequest(AcquireToken) acquireToken:completionBlock:]_block_invoke + 1808 23 Formulary 0x0000000104685388 58-[ADAuthenticationRequest(AcquireToken) requestTokenImpl:]_block_invoke_2 + 352 24 Formulary 0x0000000104686d5c 95-[ADAuthenticationRequest(AcquireToken) processOAuthResponse:telemetryEvent:completionHandler:]_block_invoke + 616 25 Formulary 0x0000000104689738 65-[ADAuthenticationRequest(WebRequest) executeRequest:completion:]_block_invoke + 200 26 Formulary 0x00000001046a1e94 -[ADWebAuthResponse handleSuccess:] + 280 27 Formulary 0x00000001046a1a50 -[ADWebAuthResponse handleJSONResponse:completionBlock:] + 492 28 Formulary 0x00000001046a14e0 -[ADWebAuthResponse handleResponse:completionBlock:] (ADWebAuthResponse.m:19670) 29 Formulary 0x00000001046a0d50 +[ADWebAuthResponse processResponse:request:completion:] (ADWebAuthResponse.m:11468) 30 Formulary 0x00000001046a0af8 32-[ADWebAuthRequest sendRequest:]_block_invoke + 80 31 Formulary 0x00000001046a2ba4 -[ADWebRequest completeWithError:andResponse:] + 128 32 Formulary 0x00000001046a30d4 -[ADWebRequest URLSession:task:didCompleteWithError:] + 104 33 CFNetwork 0x000000018e457490 _CFNetworkHTTPConnectionCacheSetLimit + 196832 34 Foundation 0x000000018b406a44 NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK + 20 35 Foundation 0x000000018b308518 -[NSBlockOperation main] + 100 36 Foundation 0x000000018b408da0 __NSOPERATION_IS_INVOKING_MAIN + 20 37 Foundation 0x000000018b308194 -[NSOperation start] + 736 38 Foundation 0x000000018b4097cc NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION + 20 39 Foundation 0x000000018b40928c __NSOQSchedule_f + 180 40 libdispatch.dylib 0x000000018ace839c _dispatch_block_async_invoke2 + 140 41 libdispatch.dylib 0x000000018acdbfd8 _dispatch_client_callout + 16 42 libdispatch.dylib 0x000000018acde758 _dispatch_continuation_pop + 404 43 libdispatch.dylib 0x000000018acddeb8 _dispatch_async_redirect_invoke + 592 44 libdispatch.dylib 0x000000018aceabd4 _dispatch_root_queue_drain + 344 45 libdispatch.dylib 0x000000018aceb384 _dispatch_worker_thread2 + 116 46 libsystem_pthread.dylib 0x000000018ad41690 _pthread_wqthread + 212 47 libsystem_pthread.dylib 0x000000018ad479e8 start_wqthread + 4
Hi. Looks like you're calling UIKit APIs from ADAL completionBlock without ensuring that you're on the main thread. ADAL doesn't guarantee that completionBlock would be invoked on a specific thread, and before you execute any UI updates, you need to ensure yourself that it is happening on the main thread.
Hello,
When calling the ADALController, performance is extremely degraded. Usually takes 5-7 seconds to launch the ADALController.
Receive the following Error: [UIViewController init] must be used from the main thread only
Stack trace is below: Main Thread Checker: UI API called on a background thread: -[UIViewController init] PID: 6650, TID: 2049663, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 0 Backtrace: 4 ADAL 0x0000000101914c54 -[MSIDWebviewUIController initWithContext:] + 92 5 ADAL 0x00000001018faa4c -[MSIDOAuth2EmbeddedWebviewController initWithStartURL:endURL:webview:customHeaders:context:] + 472 6 ADAL 0x00000001018a3280 -[MSIDAADOAuthEmbeddedWebviewController initWithStartURL:endURL:webview:customHeaders:context:] + 344 7 ADAL 0x00000001018ac004 -[MSIDAADWebviewFactory embeddedWebviewSessionFromConfiguration:customWebview:context:] + 400 8 ADAL 0x0000000101911474 +[MSIDWebviewAuthorization startEmbeddedWebviewAuthWithConfiguration:oauth2Factory:webview:context:completionHandler:] + 212 9 ADAL 0x00000001018925a4 +[ADWebAuthController(Internal) startWithRequest:promptBehavior:context:completion:] + 1788 10 ADAL 0x000000010186bf90 -[ADAuthenticationRequest(WebRequest) requestCode:] + 880 11 ADAL 0x0000000101863d78 -[ADAuthenticationRequest(AcquireToken) requestTokenImpl:] + 1272 12 ADAL 0x000000010186369c -[ADAuthenticationRequest(AcquireToken) requestToken:] + 1524 13 ADAL 0x0000000101862b34 -[ADAuthenticationRequest(AcquireToken) validatedAcquireToken:] + 448 14 ADAL 0x0000000101862374 70-[ADAuthenticationRequest(AcquireToken) acquireToken:completionBlock:]_block_invoke.160 + 656 15 ADAL 0x0000000101871408 74-[ADAuthorityValidation checkAuthority:validateAuthority:completionBlock:]_block_invoke + 276 16 ADAL 0x0000000101871bc4 __76-[ADAuthorityValidation validateAADAuthority:requestParams:completionBlock:]_block_invoke_2 + 56 17 libdispatch.dylib 0x0000000101f8d828 _dispatch_call_block_and_release + 24 18 libdispatch.dylib 0x0000000101f8ec04 _dispatch_client_callout + 16 19 libdispatch.dylib 0x0000000101f91300 _dispatch_queue_override_invoke + 872 20 libdispatch.dylib 0x0000000101fa0168 _dispatch_root_queue_drain + 376 21 libdispatch.dylib 0x0000000101fa0a90 _dispatch_worker_thread2 + 156 22 libsystem_pthread.dylib 0x0000000189837f64 _pthread_wqthread + 212 23 libsystem_pthread.dylib 0x000000018983aae0 start_wqthread + 8 2019-10-29 08:57:44.926705-0400 Aquadeptus[6650:2049663] [reports] Main Thread Checker: UI API called on a background thread: -[UIViewController init] PID: 6650, TID: 2049663, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 0 Backtrace: 4 ADAL 0x0000000101914c54 -[MSIDWebviewUIController initWithContext:] + 92 5 ADAL 0x00000001018faa4c -[MSIDOAuth2EmbeddedWebviewController initWithStartURL:endURL:webview:customHeaders:context:] + 472 6 ADAL 0x00000001018a3280 -[MSIDAADOAuthEmbeddedWebviewController initWithStartURL:endURL:webview:customHeaders:context:] + 344 7 ADAL 0x00000001018ac004 -[MSIDAADWebviewFactory embeddedWebviewSessionFromConfiguration:customWebview:context:] + 400 8 ADAL 0x0000000101911474 +[MSIDWebviewAuthorization startEmbeddedWebviewAuthWithConfiguration:oauth2Factory:webview:context:completionHandler:] + 212 9 ADAL 0x00000001018925a4 +[ADWebAuthController(Internal) startWithRequest:promptBehavior:context:completion:] + 1788 10 ADAL 0x000000010186bf90 -[ADAuthenticationRequest(WebRequest) requestCode:] + 880 11 ADAL 0x0000000101863d78 -[ADAuthenticationRequest(AcquireToken) requestTokenImpl:] + 1272 12 ADAL 0x000000010186369c -[ADAuthenticationRequest(AcquireToken) requestToken:] + 1524 13 ADAL 0x0000000101862b34 -[ADAuthenticationRequest(AcquireToken) validatedAcquireToken:] + 448 14 ADAL 0x0000000101862374 70-[ADAuthenticationRequest(AcquireToken) acquireToken:completionBlock:]_block_invoke.160 + 656 15 ADAL 0x0000000101871408 74-[ADAuthorityValidation checkAuthority:validateAuthority:completionBlock:]_block_invoke + 276 16 ADAL 0x0000000101871bc4 __76-[ADAuthorityValidation validateAADAuthority:requestParams:completionBlock:]_block_invoke_2 + 56 17 libdispatch.dylib 0x0000000101f8d828 _dispatch_call_block_and_release + 24 18 libdispatch.dylib 0x0000000101f8ec04 _dispatch_client_callout + 16 19 libdispatch.dylib 0x0000000101f91300 _dispatch_queue_override_invoke + 872 20 libdispatch.dylib 0x0000000101fa0168 _dispatch_root_queue_drain + 376 21 libdispatch.dylib 0x0000000101fa0a90 _dispatch_worker_thread2 + 156 22 libsystem_pthread.dylib 0x0000000189837f64 _pthread_wqthread + 212 23 libsystem_pthread.dylib 0x000000018983aae0 start_wqthread + 8