Make sure WebProcess::ensureNetworkProcessConnection() is always called on the main...
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Jul 2018 22:24:34 +0000 (22:24 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Jul 2018 22:24:34 +0000 (22:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=187607

Reviewed by Alex Christensen.

Add release assertion to make sure that ensureNetworkProcessConnection() is always called on the main
thread. Calling it on a background thread would not be safe. It would not be safe because:
1. We check if we have a network process connection and then create one if we don't without any locking.
2. It is not safe to construct or use a NetworkProcessConnection object from a non-main thread

* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::ensureNetworkProcessConnection):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@233784 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/inspector/InspectorInstrumentation.h
Source/WebCore/inspector/WorkerInspectorController.cpp
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/WebProcess.cpp

index 6774fe0..fcce4a7 100644 (file)
@@ -1458,6 +1458,7 @@ inline InstrumentingAgents& InspectorInstrumentation::instrumentingAgentsForWork
 
 inline void InspectorInstrumentation::frontendCreated()
 {
+    ASSERT(isMainThread());
     s_frontendCounter++;
 
     if (s_frontendCounter == 1)
@@ -1466,6 +1467,7 @@ inline void InspectorInstrumentation::frontendCreated()
 
 inline void InspectorInstrumentation::frontendDeleted()
 {
+    ASSERT(isMainThread());
     s_frontendCounter--;
 
     if (!s_frontendCounter)
index 95fe6be..aa81e01 100644 (file)
@@ -110,7 +110,9 @@ void WorkerInspectorController::connectFrontend()
 
     createLazyAgents();
 
-    InspectorInstrumentation::frontendCreated();
+    callOnMainThread([] {
+        InspectorInstrumentation::frontendCreated();
+    });
 
     m_executionStopwatch->reset();
     m_executionStopwatch->start();
@@ -127,7 +129,9 @@ void WorkerInspectorController::disconnectFrontend(Inspector::DisconnectReason r
 
     ASSERT(m_forwardingChannel);
 
-    InspectorInstrumentation::frontendDeleted();
+    callOnMainThread([] {
+        InspectorInstrumentation::frontendDeleted();
+    });
 
     m_agents.willDestroyFrontendAndBackend(reason);
     m_frontendRouter->disconnectFrontend(m_forwardingChannel.get());
index c4c518d..410d744 100644 (file)
@@ -1,5 +1,20 @@
 2018-07-12  Chris Dumez  <cdumez@apple.com>
 
+        Make sure WebProcess::ensureNetworkProcessConnection() is always called on the main thread
+        https://bugs.webkit.org/show_bug.cgi?id=187607
+
+        Reviewed by Alex Christensen.
+
+        Add release assertion to make sure that ensureNetworkProcessConnection() is always called on the main
+        thread. Calling it on a background thread would not be safe. It would not be safe because:
+        1. We check if we have a network process connection and then create one if we don't without any locking.
+        2. It is not safe to construct or use a NetworkProcessConnection object from a non-main thread
+
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::ensureNetworkProcessConnection):
+
+2018-07-12  Chris Dumez  <cdumez@apple.com>
+
         Assert that the IPC::Connection is valid in Connection::dispatchMessage(Decoder&)
         https://bugs.webkit.org/show_bug.cgi?id=187617
 
index 2c2eb28..b75d800 100644 (file)
@@ -1099,6 +1099,8 @@ void WebProcess::setInjectedBundleParameters(const IPC::DataReference& value)
 
 NetworkProcessConnection& WebProcess::ensureNetworkProcessConnection()
 {
+    RELEASE_ASSERT(RunLoop::isMain());
+
     // If we've lost our connection to the network process (e.g. it crashed) try to re-establish it.
     if (!m_networkProcessConnection) {
         IPC::Attachment encodedConnectionIdentifier;