Title: [236988] trunk/Source/WebKit
Revision
236988
Author
cdu...@apple.com
Date
2018-10-09 16:25:46 -0700 (Tue, 09 Oct 2018)

Log Message

Allow behavior when the parent process IPC::Connection closes to be overridden by ChildProcess subclasses
https://bugs.webkit.org/show_bug.cgi?id=190294

Reviewed by Geoffrey Garen.

Allow behavior when the parent process IPC::Connection closes to be overridden by ChildProcess subclasses.
This will be useful to allow the NetworkProcess to not exit if it still has pending downloads.

* NetworkProcess/NetworkProcess.cpp:
(WebKit::callExitSoon):
(WebKit::NetworkProcess::initializeConnection):
* NetworkProcess/NetworkProcess.h:
* PluginProcess/PluginProcess.cpp:
(WebKit::callExit):
(WebKit::PluginProcess::initializeConnection):
* PluginProcess/PluginProcess.h:
* Shared/ChildProcess.cpp:
(WebKit::ChildProcess::didClose):
(WebKit::ChildProcess::initialize):
(WebKit::callExitNow): Deleted.
(WebKit::callExitSoon): Deleted.
* Shared/ChildProcess.h:
(WebKit::ChildProcess::shouldCallExitWhenConnectionIsClosed const): Deleted.
* WebProcess/WebProcess.cpp:
(WebKit::callExit):
(WebKit::WebProcess::initializeConnection):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (236987 => 236988)


--- trunk/Source/WebKit/ChangeLog	2018-10-09 23:21:18 UTC (rev 236987)
+++ trunk/Source/WebKit/ChangeLog	2018-10-09 23:25:46 UTC (rev 236988)
@@ -1,3 +1,32 @@
+2018-10-09  Chris Dumez  <cdu...@apple.com>
+
+        Allow behavior when the parent process IPC::Connection closes to be overridden by ChildProcess subclasses
+        https://bugs.webkit.org/show_bug.cgi?id=190294
+
+        Reviewed by Geoffrey Garen.
+
+        Allow behavior when the parent process IPC::Connection closes to be overridden by ChildProcess subclasses.
+        This will be useful to allow the NetworkProcess to not exit if it still has pending downloads.
+
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::callExitSoon):
+        (WebKit::NetworkProcess::initializeConnection):
+        * NetworkProcess/NetworkProcess.h:
+        * PluginProcess/PluginProcess.cpp:
+        (WebKit::callExit):
+        (WebKit::PluginProcess::initializeConnection):
+        * PluginProcess/PluginProcess.h:
+        * Shared/ChildProcess.cpp:
+        (WebKit::ChildProcess::didClose):
+        (WebKit::ChildProcess::initialize):
+        (WebKit::callExitNow): Deleted.
+        (WebKit::callExitSoon): Deleted.
+        * Shared/ChildProcess.h:
+        (WebKit::ChildProcess::shouldCallExitWhenConnectionIsClosed const): Deleted.
+        * WebProcess/WebProcess.cpp:
+        (WebKit::callExit):
+        (WebKit::WebProcess::initializeConnection):
+
 2018-10-09  Jer Noble  <jer.no...@apple.com>
 
         WebDriver: thrown ObjC exception under -[WKFullScreenWindowController windowDidFailToEnterFullScreen:] when session is terminated

Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp (236987 => 236988)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2018-10-09 23:21:18 UTC (rev 236987)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2018-10-09 23:25:46 UTC (rev 236988)
@@ -108,6 +108,21 @@
 namespace WebKit {
 using namespace WebCore;
 
+static void callExitSoon(IPC::Connection*)
+{
+    // If the connection has been closed and we haven't responded in the main thread for 10 seconds
+    // the process will exit forcibly.
+    auto watchdogDelay = 10_s;
+
+    WorkQueue::create("com.apple.WebKit.ChildProcess.WatchDogQueue")->dispatchAfter(watchdogDelay, [] {
+        // We use _exit here since the watchdog callback is called from another thread and we don't want
+        // global destructors or atexit handlers to be called from this thread while the main thread is busy
+        // doing its thing.
+        RELEASE_LOG_ERROR(IPC, "Exiting process early due to unacknowledged closed-connection");
+        _exit(EXIT_FAILURE);
+    });
+}
+
 NetworkProcess& NetworkProcess::singleton()
 {
     static NeverDestroyed<NetworkProcess> networkProcess;
@@ -359,6 +374,10 @@
 {
     ChildProcess::initializeConnection(connection);
 
+    // We give a chance for didClose() to get called on the main thread but forcefully call _exit() after a delay
+    // in case the main thread is unresponsive or didClose() takes too long.
+    connection->setDidCloseOnConnectionWorkQueueCallback(callExitSoon);
+
     for (auto& supplement : m_supplements.values())
         supplement->initializeConnection(connection);
 }

Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.h (236987 => 236988)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.h	2018-10-09 23:21:18 UTC (rev 236987)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.h	2018-10-09 23:25:46 UTC (rev 236988)
@@ -246,7 +246,6 @@
     void initializeSandbox(const ChildProcessInitializationParameters&, SandboxInitializationParameters&) override;
     void initializeConnection(IPC::Connection*) override;
     bool shouldTerminate() override;
-    bool shouldCallExitWhenConnectionIsClosed() const final { return false; } // We override didClose() and want it to be called.
 
     // IPC::Connection::Client
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;

Modified: trunk/Source/WebKit/PluginProcess/PluginProcess.cpp (236987 => 236988)


--- trunk/Source/WebKit/PluginProcess/PluginProcess.cpp	2018-10-09 23:21:18 UTC (rev 236987)
+++ trunk/Source/WebKit/PluginProcess/PluginProcess.cpp	2018-10-09 23:25:46 UTC (rev 236988)
@@ -52,6 +52,11 @@
 
 namespace WebKit {
 
+NO_RETURN static void callExit(IPC::Connection*)
+{
+    _exit(EXIT_SUCCESS);
+}
+
 PluginProcess& PluginProcess::singleton()
 {
     static NeverDestroyed<PluginProcess> pluginProcess;
@@ -78,6 +83,15 @@
     platformInitializeProcess(parameters);
 }
 
+void PluginProcess::initializeConnection(IPC::Connection* connection)
+{
+    ChildProcess::initializeConnection(connection);
+
+    // We call _exit() directly from the background queue in case the main thread is unresponsive
+    // and ChildProcess::didClose() does not get called.
+    connection->setDidCloseOnConnectionWorkQueueCallback(callExit);
+}
+
 void PluginProcess::removeWebProcessConnection(WebProcessConnection* webProcessConnection)
 {
     size_t vectorIndex = m_webProcessConnections.find(webProcessConnection);

Modified: trunk/Source/WebKit/PluginProcess/PluginProcess.h (236987 => 236988)


--- trunk/Source/WebKit/PluginProcess/PluginProcess.h	2018-10-09 23:21:18 UTC (rev 236987)
+++ trunk/Source/WebKit/PluginProcess/PluginProcess.h	2018-10-09 23:25:46 UTC (rev 236988)
@@ -82,6 +82,7 @@
     // ChildProcess
     void initializeProcess(const ChildProcessInitializationParameters&) override;
     void initializeProcessName(const ChildProcessInitializationParameters&) override;
+    void initializeConnection(IPC::Connection*) override;
     void initializeSandbox(const ChildProcessInitializationParameters&, SandboxInitializationParameters&) override;
     bool shouldTerminate() override;
     void platformInitializeProcess(const ChildProcessInitializationParameters&);

Modified: trunk/Source/WebKit/Shared/ChildProcess.cpp (236987 => 236988)


--- trunk/Source/WebKit/Shared/ChildProcess.cpp	2018-10-09 23:21:18 UTC (rev 236987)
+++ trunk/Source/WebKit/Shared/ChildProcess.cpp	2018-10-09 23:25:46 UTC (rev 236988)
@@ -56,28 +56,9 @@
 
 void ChildProcess::didClose(IPC::Connection&)
 {
-}
-
-NO_RETURN static void callExitNow(IPC::Connection*)
-{
     _exit(EXIT_SUCCESS);
 }
 
-static void callExitSoon(IPC::Connection*)
-{
-    // If the connection has been closed and we haven't responded in the main thread for 10 seconds
-    // the process will exit forcibly.
-    auto watchdogDelay = 10_s;
-
-    WorkQueue::create("com.apple.WebKit.ChildProcess.WatchDogQueue")->dispatchAfter(watchdogDelay, [] {
-        // We use _exit here since the watchdog callback is called from another thread and we don't want
-        // global destructors or atexit handlers to be called from this thread while the main thread is busy
-        // doing its thing.
-        RELEASE_LOG_ERROR(IPC, "Exiting process early due to unacknowledged closed-connection");
-        _exit(EXIT_FAILURE);
-    });
-}
-
 void ChildProcess::initialize(const ChildProcessInitializationParameters& parameters)
 {
     RELEASE_ASSERT_WITH_MESSAGE(parameters.processIdentifier, "Unable to initialize child process without a WebCore process identifier");
@@ -99,11 +80,6 @@
     PAL::SessionID::enableGenerationProtection();
 
     m_connection = IPC::Connection::createClientConnection(parameters.connectionIdentifier, *this);
-    if (shouldCallExitWhenConnectionIsClosed())
-        m_connection->setDidCloseOnConnectionWorkQueueCallback(callExitNow);
-    else
-        m_connection->setDidCloseOnConnectionWorkQueueCallback(callExitSoon);
-
     initializeConnection(m_connection.get());
     m_connection->open();
 }

Modified: trunk/Source/WebKit/Shared/ChildProcess.h (236987 => 236988)


--- trunk/Source/WebKit/Shared/ChildProcess.h	2018-10-09 23:21:18 UTC (rev 236987)
+++ trunk/Source/WebKit/Shared/ChildProcess.h	2018-10-09 23:25:46 UTC (rev 236988)
@@ -95,7 +95,6 @@
     virtual bool shouldTerminate() = 0;
     virtual void terminate();
 
-    virtual bool shouldCallExitWhenConnectionIsClosed() const { return true; }
     virtual void stopRunLoop();
 
 #if USE(APPKIT)

Modified: trunk/Source/WebKit/WebProcess/WebProcess.cpp (236987 => 236988)


--- trunk/Source/WebKit/WebProcess/WebProcess.cpp	2018-10-09 23:21:18 UTC (rev 236987)
+++ trunk/Source/WebKit/WebProcess/WebProcess.cpp	2018-10-09 23:25:46 UTC (rev 236988)
@@ -157,6 +157,11 @@
 using namespace JSC;
 using namespace WebCore;
 
+NO_RETURN static void callExit(IPC::Connection*)
+{
+    _exit(EXIT_SUCCESS);
+}
+
 WebProcess& WebProcess::singleton()
 {
     static WebProcess& process = *new WebProcess;
@@ -227,6 +232,10 @@
 {
     ChildProcess::initializeConnection(connection);
 
+    // We call _exit() directly from the background queue in case the main thread is unresponsive
+    // and ChildProcess::didClose() does not get called.
+    connection->setDidCloseOnConnectionWorkQueueCallback(callExit);
+
 #if !PLATFORM(GTK) && !PLATFORM(WPE)
     connection->setShouldExitOnSyncMessageSendFailure(true);
 #endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to