Title: [169375] releases/WebKitGTK/webkit-2.4
Revision
169375
Author
carlo...@webkit.org
Date
2014-05-27 02:43:04 -0700 (Tue, 27 May 2014)

Log Message

Merge r169352 - [GTK] WebProcess leaked when closing pages with network process enabled
https://bugs.webkit.org/show_bug.cgi?id=129684

Reviewed by Anders Carlsson.

Source/WebKit2:
The problem is that the web process is not notified when the UI
process closes the connection, because when close() is called on
the socket by the UI process, the socket is shared by another web
process launched later, preventing the connection from being
shut down. We need to set the CLOEXEC flag on the sockets file
descriptor to make sure they are not exposed to other processes.

* Platform/IPC/Connection.h: Add ConnectionOptions parameter to
createPlatformConnection() with a default value compatible with
existing callers.
* Platform/IPC/unix/ConnectionUnix.cpp:
(IPC::Connection::createPlatformConnection): Set the CLOEXEC flag
on the client and server socket file descriptors depending on the
options passed.
* UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp:
(WebKit::ProcessLauncher::launchProcess): Use
IPC::Connection::createPlatformConnection() instead of
socketpair() directly, setting the CLOEXEC flag on the server
before spawning the new process and on the client right after
spawning the new process.

Tools:
Enable the test to check that web processes finish when the web
view is destroyed.

* TestWebKitAPI/Tests/WebKit2Gtk/TestMultiprocess.cpp:

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.4/Source/WebKit2/ChangeLog (169374 => 169375)


--- releases/WebKitGTK/webkit-2.4/Source/WebKit2/ChangeLog	2014-05-27 09:06:11 UTC (rev 169374)
+++ releases/WebKitGTK/webkit-2.4/Source/WebKit2/ChangeLog	2014-05-27 09:43:04 UTC (rev 169375)
@@ -1,3 +1,31 @@
+2014-05-26  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK] WebProcess leaked when closing pages with network process enabled
+        https://bugs.webkit.org/show_bug.cgi?id=129684
+
+        Reviewed by Anders Carlsson.
+
+        The problem is that the web process is not notified when the UI
+        process closes the connection, because when close() is called on
+        the socket by the UI process, the socket is shared by another web
+        process launched later, preventing the connection from being
+        shut down. We need to set the CLOEXEC flag on the sockets file
+        descriptor to make sure they are not exposed to other processes.
+
+        * Platform/IPC/Connection.h: Add ConnectionOptions parameter to
+        createPlatformConnection() with a default value compatible with
+        existing callers.
+        * Platform/IPC/unix/ConnectionUnix.cpp:
+        (IPC::Connection::createPlatformConnection): Set the CLOEXEC flag
+        on the client and server socket file descriptors depending on the
+        options passed.
+        * UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp:
+        (WebKit::ProcessLauncher::launchProcess): Use
+        IPC::Connection::createPlatformConnection() instead of
+        socketpair() directly, setting the CLOEXEC flag on the server
+        before spawning the new process and on the client right after
+        spawning the new process.
+
 2014-05-20  Carlos Garcia Campos  <cgar...@igalia.com>
 
         [GTK] WebKitWebPage::send-request always pass a valid pointer for redirected response

Modified: releases/WebKitGTK/webkit-2.4/Source/WebKit2/Platform/IPC/Connection.h (169374 => 169375)


--- releases/WebKitGTK/webkit-2.4/Source/WebKit2/Platform/IPC/Connection.h	2014-05-27 09:06:11 UTC (rev 169374)
+++ releases/WebKitGTK/webkit-2.4/Source/WebKit2/Platform/IPC/Connection.h	2014-05-27 09:43:04 UTC (rev 169375)
@@ -122,7 +122,12 @@
         int server;
     };
 
-    static Connection::SocketPair createPlatformConnection();
+    enum ConnectionOptions {
+        SetCloexecOnClient = 1 << 0,
+        SetCloexecOnServer = 1 << 1,
+    };
+
+    static Connection::SocketPair createPlatformConnection(unsigned options = SetCloexecOnClient | SetCloexecOnServer);
 #endif
 
     static PassRefPtr<Connection> createServerConnection(Identifier, Client*, WTF::RunLoop* clientRunLoop);

Modified: releases/WebKitGTK/webkit-2.4/Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp (169374 => 169375)


--- releases/WebKitGTK/webkit-2.4/Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp	2014-05-27 09:06:11 UTC (rev 169374)
+++ releases/WebKitGTK/webkit-2.4/Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp	2014-05-27 09:43:04 UTC (rev 169375)
@@ -541,18 +541,22 @@
     return true;
 }
 
-Connection::SocketPair Connection::createPlatformConnection()
+Connection::SocketPair Connection::createPlatformConnection(unsigned options)
 {
     int sockets[2];
     RELEASE_ASSERT(socketpair(AF_UNIX, SOCKET_TYPE, 0, sockets) != -1);
 
-    // Don't expose the child socket to the parent process.
-    while (fcntl(sockets[1], F_SETFD, FD_CLOEXEC)  == -1)
-        RELEASE_ASSERT(errno != EINTR);
+    if (options & SetCloexecOnServer) {
+        // Don't expose the child socket to the parent process.
+        while (fcntl(sockets[1], F_SETFD, FD_CLOEXEC)  == -1)
+            RELEASE_ASSERT(errno != EINTR);
+    }
 
-    // Don't expose the parent socket to potential future children.
-    while (fcntl(sockets[0], F_SETFD, FD_CLOEXEC) == -1)
-        RELEASE_ASSERT(errno != EINTR);
+    if (options & SetCloexecOnClient) {
+        // Don't expose the parent socket to potential future children.
+        while (fcntl(sockets[0], F_SETFD, FD_CLOEXEC) == -1)
+            RELEASE_ASSERT(errno != EINTR);
+    }
 
     SocketPair socketPair = { sockets[0], sockets[1] };
     return socketPair;

Modified: releases/WebKitGTK/webkit-2.4/Source/WebKit2/UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp (169374 => 169375)


--- releases/WebKitGTK/webkit-2.4/Source/WebKit2/UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp	2014-05-27 09:06:11 UTC (rev 169374)
+++ releases/WebKitGTK/webkit-2.4/Source/WebKit2/UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp	2014-05-27 09:43:04 UTC (rev 169375)
@@ -34,6 +34,7 @@
 #include <WebCore/NetworkingContext.h>
 #include <WebCore/ResourceHandle.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <glib.h>
 #include <locale.h>
 #include <wtf/RunLoop.h>
@@ -42,16 +43,6 @@
 #include <wtf/gobject/GUniquePtr.h>
 #include <wtf/gobject/GlibUtilities.h>
 
-#if OS(UNIX)
-#include <sys/socket.h>
-#endif
-
-#ifdef SOCK_SEQPACKET
-#define SOCKET_TYPE SOCK_SEQPACKET
-#else
-#define SOCKET_TYPE SOCK_STREAM
-#endif
-
 using namespace WebCore;
 
 namespace WebKit {
@@ -66,12 +57,7 @@
 {
     GPid pid = 0;
 
-    int sockets[2];
-    if (socketpair(AF_UNIX, SOCKET_TYPE, 0, sockets) < 0) {
-        g_printerr("Creation of socket failed: %s.\n", g_strerror(errno));
-        ASSERT_NOT_REACHED();
-        return;
-    }
+    IPC::Connection::SocketPair socketPair = IPC::Connection::createPlatformConnection(IPC::Connection::ConnectionOptions::SetCloexecOnServer);
 
     String executablePath, pluginPath;
     CString realExecutablePath, realPluginPath;
@@ -95,7 +81,7 @@
     }
 
     realExecutablePath = fileSystemRepresentation(executablePath);
-    GUniquePtr<gchar> socket(g_strdup_printf("%d", sockets[0]));
+    GUniquePtr<gchar> socket(g_strdup_printf("%d", socketPair.client));
 
     unsigned nargs = 4; // size of the argv array for g_spawn_async()
 
@@ -123,16 +109,20 @@
     argv[i++] = 0;
 
     GUniqueOutPtr<GError> error;
-    if (!g_spawn_async(0, argv, 0, G_SPAWN_LEAVE_DESCRIPTORS_OPEN, childSetupFunction, GINT_TO_POINTER(sockets[1]), &pid, &error.outPtr())) {
+    if (!g_spawn_async(0, argv, 0, G_SPAWN_LEAVE_DESCRIPTORS_OPEN, childSetupFunction, GINT_TO_POINTER(socketPair.server), &pid, &error.outPtr())) {
         g_printerr("Unable to fork a new WebProcess: %s.\n", error->message);
         ASSERT_NOT_REACHED();
     }
 
-    close(sockets[0]);
+    // Don't expose the parent socket to potential future children.
+    while (fcntl(socketPair.client, F_SETFD, FD_CLOEXEC) == -1)
+        RELEASE_ASSERT(errno != EINTR);
+
+    close(socketPair.client);
     m_processIdentifier = pid;
 
     // We've finished launching the process, message back to the main run loop.
-    RunLoop::main()->dispatch(bind(&ProcessLauncher::didFinishLaunchingProcess, this, m_processIdentifier, sockets[1]));
+    RunLoop::main()->dispatch(bind(&ProcessLauncher::didFinishLaunchingProcess, this, m_processIdentifier, socketPair.server));
 }
 
 void ProcessLauncher::terminateProcess()

Modified: releases/WebKitGTK/webkit-2.4/Tools/ChangeLog (169374 => 169375)


--- releases/WebKitGTK/webkit-2.4/Tools/ChangeLog	2014-05-27 09:06:11 UTC (rev 169374)
+++ releases/WebKitGTK/webkit-2.4/Tools/ChangeLog	2014-05-27 09:43:04 UTC (rev 169375)
@@ -1,5 +1,17 @@
 2014-05-26  Carlos Garcia Campos  <cgar...@igalia.com>
 
+        [GTK] WebProcess leaked when closing pages with network process enabled
+        https://bugs.webkit.org/show_bug.cgi?id=129684
+
+        Reviewed by Anders Carlsson.
+
+        Enable the test to check that web processes finish when the web
+        view is destroyed.
+
+        * TestWebKitAPI/Tests/WebKit2Gtk/TestMultiprocess.cpp:
+
+2014-05-26  Carlos Garcia Campos  <cgar...@igalia.com>
+
         Unreviewed. Fix make distcheck.
 
         * gtk/GNUmakefile.am: Remove generate-webkitdom-doc-files from

Modified: releases/WebKitGTK/webkit-2.4/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestMultiprocess.cpp (169374 => 169375)


--- releases/WebKitGTK/webkit-2.4/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestMultiprocess.cpp	2014-05-27 09:06:11 UTC (rev 169374)
+++ releases/WebKitGTK/webkit-2.4/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestMultiprocess.cpp	2014-05-27 09:43:04 UTC (rev 169375)
@@ -90,7 +90,6 @@
     {
         // FIXME: This test is disabled because the web processed don't actually die
         // due to bug https://bugs.webkit.org/show_bug.cgi?id=129684.
-#if 0
         g_assert_cmpuint(index, <, numViews);
 
         unsigned watcherID = g_bus_watch_name_on_connection(bus->connection(), m_webViewBusNames[index].get(), G_BUS_NAME_WATCHER_FLAGS_NONE,
@@ -98,7 +97,6 @@
         gtk_widget_destroy(GTK_WIDGET(m_webViews[index].get()));
         g_main_loop_run(m_mainLoop);
         g_bus_unwatch_name(watcherID);
-#endif
     }
 
     GMainLoop* m_mainLoop;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to