mozilla-mobile / firefox-ios

Firefox for iOS
Mozilla Public License 2.0
12.09k stars 2.88k forks source link

Runtime warnings in Xcode because BrowserViewController.handleServerTrust calls SecTrustCopyCertificateChain on the main thread: "This method should not be called on the main thread as it may lead to UI unresponsiveness." #19285

Open mstange opened 3 months ago

mstange commented 3 months ago

When running the app from Xcode, I see a lot of messages of the following form in the console:

"This method should not be called on the main thread as it may lead to UI unresponsiveness."

I've tracked these down to the call to SecTrustCopyCertificateChain in BrowserViewController.handleServerTrust:

https://github.com/mozilla-mobile/firefox-ios/blob/9f9df113a90844782efa12252e963993f2ab32d3/firefox-ios/Client/Frontend/Browser/BrowserViewController/Extensions/BrowserViewController%2BWebViewDelegates.swift#L1042-L1058

In the past, WebKit was triggering this warning internally (see #12514), but the warnings I see are definitely caused by Firefox.

Stack:

#0  0x0000000181be29f0 in SecTrustCopyCertificateChain ()
#1  0x0000000102feace4 in BrowserViewController.handleServerTrust(challenge:completionHandler:) at /Users/mstange/code/firefox-ios/firefox-ios/Client/Frontend/Browser/BrowserViewController/Extensions/BrowserViewController+WebViewDelegates.swift:1049
#2  0x0000000102fea9b0 in BrowserViewController.webView(_:didReceive:completionHandler:) at /Users/mstange/code/firefox-ios/firefox-ios/Client/Frontend/Browser/BrowserViewController/Extensions/BrowserViewController+WebViewDelegates.swift:837
#3  0x0000000102feb35c in @objc BrowserViewController.webView(_:didReceive:completionHandler:) ()
#4  0x0000000102b83884 in partial apply ()
#5  0x0000000102b836c4 in thunk for @escaping @callee_guaranteed (@unowned WKWebView, @unowned NSURLAuthenticationChallenge, @unowned @escaping @callee_unowned @convention(block) (@unowned NSURLSessionAuthChallengeDisposition, @unowned NSURLCredential?) -> ()) -> () ()
#6  0x0000000102b8342c in TabManagerNavDelegate.webView(_:didReceive:completionHandler:) at /Users/mstange/code/firefox-ios/firefox-ios/Client/TabManagement/TabManagerNavDelegate.swift:68
#7  0x0000000102b83964 in @objc TabManagerNavDelegate.webView(_:didReceive:completionHandler:) ()
#8  0x000000018b400028 in WebKit::NavigationState::NavigationClient::didReceiveAuthenticationChallenge(WebKit::WebPageProxy&, WebKit::AuthenticationChallengeProxy&) ()
#9  0x000000018b65fbe8 in WebKit::NetworkProcessProxy::didReceiveAuthenticationChallenge(PAL::SessionID, WTF::ObjectIdentifierGeneric<WebKit::WebPageProxyIdentifierType, WTF::ObjectIdentifierMainThreadAccessTraits>, std::__1::optional<WebCore::SecurityOriginData> const&, WebCore::AuthenticationChallenge&&, bool, WTF::ObjectIdentifierGeneric<WebKit::AuthenticationChallengeIdentifierType, WTF::ObjectIdentifierMainThreadAccessTraits>) ()
#10 0x000000018b130078 in WebKit::NetworkProcessProxy::didReceiveNetworkProcessProxyMessage(IPC::Connection&, IPC::Decoder&) ()
#11 0x000000018bad0848 in IPC::Connection::dispatchMessage(std::__1::unique_ptr<IPC::Decoder, std::__1::default_delete<IPC::Decoder>>) ()
#12 0x000000018bad2b58 in WTF::Detail::CallableWrapper<IPC::Connection::enqueueIncomingMessage(std::__1::unique_ptr<IPC::Decoder, std::__1::default_delete<IPC::Decoder>>)::$_15, void>::call() ()
#13 0x00000001953a8314 in WTF::RunLoop::performWork() ()
#14 0x00000001953a9068 in WTF::RunLoop::performWork(void*) ()
#15 0x000000018040ee88 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ ()
#16 0x000000018040edd0 in __CFRunLoopDoSource0 ()
#17 0x000000018040e540 in __CFRunLoopDoSources0 ()
#18 0x0000000180408c28 in __CFRunLoopRun ()
#19 0x0000000180408514 in CFRunLoopRunSpecific ()
#20 0x000000018ef06ae4 in GSEventRunModal ()
#21 0x00000001853e8040 in -[UIApplication _run] ()
#22 0x00000001853ebcc8 in UIApplicationMain ()
#23 0x000000010336a9f8 in main at /Users/mstange/code/firefox-ios/firefox-ios/Client/Application/main.swift:25
#24 0x0000000107319544 in start_sim ()
#25 0x0000000106cc60e0 in start ()

┆Issue is synchronized with this Jira Task

data-sync-user commented 3 months ago

➤ Norberto Andres Furlan commented:

Clare So can you take a look to this one?

data-sync-user commented 3 months ago

➤ Clare So commented:

Norberto Andres Furlan Sorry, I have not encountered such an error message.

mstange commented 3 months ago

I see this warning when I visit any website in Firefox in the iOS simulator.

I'm using Xcode 15.3.

data-sync-user commented 2 months ago

➤ Stefan Vladut commented:

for QA, try loading several websites with SSL certs and if they load with no issues and no UI hangs then it’s good

data-sync-user commented 2 months ago

➤ Diana Andreea Barladeanu commented:

Validated on v126 (41303), with iPhone 15 (17.4).