1

Recently I encountered a WebKit crash problem, it is related to thread checking

0   WebKit  WTFCrashWithInfo(int, char const*, char const*, int)()       
1   WebKit  WebKit::isMainThreadOrCheckDisabled()()       
2   WebKit  WebKit::WebProcessPool::createNewWebProcess(WebKit::WebsiteDataStore*, WebKit::WebProcessProxy::IsPrewarmed)()       
3   WebKit  WebKit::WebProcessPool::processForRegistrableDomain(WebKit::WebsiteDataStore&, WebKit::WebPageProxy*, WebCore::RegistrableDomain const&)()       
4   WebKit  WebKit::WebProcessPool::createWebPage(WebKit::PageClient&, WTF::Ref<API::PageConfiguration, WTF::DumbPtrTraits<API::PageConfiguration> >&&)()       
5   WebKit  -[WKContentView _commonInitializationWithProcessPool:configuration:]()       
6   WebKit  -[WKContentView initWithFrame:processPool:configuration:webView:]()       
7   WebKit  -[WKWebView _initializeWithConfiguration:]()       
8   WebKit  -[WKWebView initWithFrame:configuration:]()       

I am sure the WKWebView was initialized on Main Thread, but isMainThreadOrCheckDisabled shows isn't. I even read the source code of WebKit, not able to find isMainThreadOrCheckDisabled be called in createNewWebProcess ,so do you have any idea?


After further reading the source code of WebKit, I find out isMainThreadOrCheckDisabled check thread by RunLoop actually, which is

bool RunLoop::isMain()
{
    ASSERT(s_mainRunLoop);
    return s_mainRunLoop == &RunLoop::current();
}

and the &RunLoop::current() represents current thread, so s_mainRunLoop means Main Thread, because it is initialized on it

void RunLoop::initializeMain()
{
    RELEASE_ASSERT(!s_mainRunLoop);
    s_mainRunLoop = &RunLoop::current();
}

So, when run isMainThreadOrCheckDisabled on a background thread, it return false.

But the crash I encountered was happened on Main Thread, dose it means s_mainRunLoop not initialized on Main Thread? Or, is there any situation can WebKit be initialized on background thread?

0 Answers0