Title: [285720] trunk
Revision
285720
Author
[email protected]
Date
2021-11-12 08:18:51 -0800 (Fri, 12 Nov 2021)

Log Message

WebKit is unable to recover if a WebProcess gets terminated while it is launching
https://bugs.webkit.org/show_bug.cgi?id=233001
<rdar://85302938>

Reviewed by Brent Fulgham.

Source/WebKit:

While investigating <rdar://83941760>, I found that the WebAuthn Process would get
jetsammed, which would cause us to call WebProcessPool::terminateAllWebContentProcesses().
I also noticed that if one of these WebProcesses was still launching at the time
of the termination, then the WebProcessProxy / WebPageProxy would keep thinking the
WebProcess is still launching and would never attempt to relaunch it. This would result
in a blank and unresponsive WKWebView which wouldn't be able to do any loads.

The issue was due to ProcessLauncher::terminateProcess() calling invalidate(), which
it would not only terminate the XPC connection, it would also null out m_client. As a
result, we wouldn't notify the client that the process failed to launch. To address
the issue, I move the XPC connection termination logic out of invalidate() and into
its own terminateXPCConnection() function. I then called terminateXPCConnection()
instead of invalidate() inside ProcessLauncher::terminateProcess().

* UIProcess/API/Cocoa/WKProcessPool.mm:
(-[WKProcessPool _terminateAllWebContentProcesses]):
* UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
* UIProcess/Launcher/ProcessLauncher.cpp:
(WebKit::ProcessLauncher::invalidate):
* UIProcess/Launcher/ProcessLauncher.h:
* UIProcess/Launcher/mac/ProcessLauncherMac.mm:
(WebKit::ProcessLauncher::terminateProcess):
(WebKit::ProcessLauncher::platformInvalidate):
(WebKit::ProcessLauncher::terminateXPCConnection):

Tools:

Add API test coverage, this test was timing out before the fix.

* TestWebKitAPI/Tests/WebKitCocoa/WebProcessTerminate.mm:
(TEST):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (285719 => 285720)


--- trunk/Source/WebKit/ChangeLog	2021-11-12 15:59:24 UTC (rev 285719)
+++ trunk/Source/WebKit/ChangeLog	2021-11-12 16:18:51 UTC (rev 285720)
@@ -1,5 +1,38 @@
 2021-11-12  Chris Dumez  <[email protected]>
 
+        WebKit is unable to recover if a WebProcess gets terminated while it is launching
+        https://bugs.webkit.org/show_bug.cgi?id=233001
+        <rdar://85302938>
+
+        Reviewed by Brent Fulgham.
+
+        While investigating <rdar://83941760>, I found that the WebAuthn Process would get
+        jetsammed, which would cause us to call WebProcessPool::terminateAllWebContentProcesses().
+        I also noticed that if one of these WebProcesses was still launching at the time
+        of the termination, then the WebProcessProxy / WebPageProxy would keep thinking the
+        WebProcess is still launching and would never attempt to relaunch it. This would result
+        in a blank and unresponsive WKWebView which wouldn't be able to do any loads.
+
+        The issue was due to ProcessLauncher::terminateProcess() calling invalidate(), which
+        it would not only terminate the XPC connection, it would also null out m_client. As a
+        result, we wouldn't notify the client that the process failed to launch. To address
+        the issue, I move the XPC connection termination logic out of invalidate() and into
+        its own terminateXPCConnection() function. I then called terminateXPCConnection()
+        instead of invalidate() inside ProcessLauncher::terminateProcess().
+
+        * UIProcess/API/Cocoa/WKProcessPool.mm:
+        (-[WKProcessPool _terminateAllWebContentProcesses]):
+        * UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
+        * UIProcess/Launcher/ProcessLauncher.cpp:
+        (WebKit::ProcessLauncher::invalidate):
+        * UIProcess/Launcher/ProcessLauncher.h:
+        * UIProcess/Launcher/mac/ProcessLauncherMac.mm:
+        (WebKit::ProcessLauncher::terminateProcess):
+        (WebKit::ProcessLauncher::platformInvalidate):
+        (WebKit::ProcessLauncher::terminateXPCConnection):
+
+2021-11-12  Chris Dumez  <[email protected]>
+
         Disable getUserMedia() when in Captive Portal Mode
         https://bugs.webkit.org/show_bug.cgi?id=233021
 

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm (285719 => 285720)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm	2021-11-12 15:59:24 UTC (rev 285719)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm	2021-11-12 16:18:51 UTC (rev 285720)
@@ -590,4 +590,9 @@
     _processPool->setUsesOnlyHIDGamepadProviderForTesting(usesHIDProvider);
 }
 
+- (void)_terminateAllWebContentProcesses
+{
+    _processPool->terminateAllWebContentProcesses();
+}
+
 @end

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h (285719 => 285720)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h	2021-11-12 15:59:24 UTC (rev 285719)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h	2021-11-12 16:18:51 UTC (rev 285720)
@@ -98,6 +98,8 @@
 // Test only.
 - (pid_t)_prewarmedProcessIdentifier WK_API_AVAILABLE(macos(10.15), ios(13.0));
 
+- (void)_terminateAllWebContentProcesses;
+
 // Test only.
 - (size_t)_webProcessCount WK_API_AVAILABLE(macos(10.13), ios(11.0));
 - (BOOL)_hasPrewarmedWebProcess WK_API_AVAILABLE(macos(10.14.4), ios(12.2));

Modified: trunk/Source/WebKit/UIProcess/Launcher/ProcessLauncher.cpp (285719 => 285720)


--- trunk/Source/WebKit/UIProcess/Launcher/ProcessLauncher.cpp	2021-11-12 15:59:24 UTC (rev 285719)
+++ trunk/Source/WebKit/UIProcess/Launcher/ProcessLauncher.cpp	2021-11-12 16:18:51 UTC (rev 285720)
@@ -61,7 +61,7 @@
 
 void ProcessLauncher::invalidate()
 {
-    m_client = 0;
+    m_client = nullptr;
     platformInvalidate();
 }
 

Modified: trunk/Source/WebKit/UIProcess/Launcher/ProcessLauncher.h (285719 => 285720)


--- trunk/Source/WebKit/UIProcess/Launcher/ProcessLauncher.h	2021-11-12 15:59:24 UTC (rev 285719)
+++ trunk/Source/WebKit/UIProcess/Launcher/ProcessLauncher.h	2021-11-12 16:18:51 UTC (rev 285720)
@@ -122,6 +122,10 @@
 
     void platformInvalidate();
 
+#if PLATFORM(COCOA)
+    void terminateXPCConnection();
+#endif
+
     Client* m_client;
 
 #if PLATFORM(COCOA)

Modified: trunk/Source/WebKit/UIProcess/Launcher/mac/ProcessLauncherMac.mm (285719 => 285720)


--- trunk/Source/WebKit/UIProcess/Launcher/mac/ProcessLauncherMac.mm	2021-11-12 15:59:24 UTC (rev 285719)
+++ trunk/Source/WebKit/UIProcess/Launcher/mac/ProcessLauncherMac.mm	2021-11-12 16:18:51 UTC (rev 285720)
@@ -322,7 +322,7 @@
 void ProcessLauncher::terminateProcess()
 {
     if (m_isLaunching) {
-        invalidate();
+        terminateXPCConnection();
         return;
     }
 
@@ -335,6 +335,11 @@
     
 void ProcessLauncher::platformInvalidate()
 {
+    terminateXPCConnection();
+}
+
+void ProcessLauncher::terminateXPCConnection()
+{
     if (!m_xpcConnection)
         return;
 

Modified: trunk/Tools/ChangeLog (285719 => 285720)


--- trunk/Tools/ChangeLog	2021-11-12 15:59:24 UTC (rev 285719)
+++ trunk/Tools/ChangeLog	2021-11-12 16:18:51 UTC (rev 285720)
@@ -1,5 +1,18 @@
 2021-11-12  Chris Dumez  <[email protected]>
 
+        WebKit is unable to recover if a WebProcess gets terminated while it is launching
+        https://bugs.webkit.org/show_bug.cgi?id=233001
+        <rdar://85302938>
+
+        Reviewed by Brent Fulgham.
+
+        Add API test coverage, this test was timing out before the fix.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WebProcessTerminate.mm:
+        (TEST):
+
+2021-11-12  Chris Dumez  <[email protected]>
+
         Disable getUserMedia() when in Captive Portal Mode
         https://bugs.webkit.org/show_bug.cgi?id=233021
 

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebProcessTerminate.mm (285719 => 285720)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebProcessTerminate.mm	2021-11-12 15:59:24 UTC (rev 285719)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebProcessTerminate.mm	2021-11-12 16:18:51 UTC (rev 285720)
@@ -29,6 +29,7 @@
 #import "Test.h"
 #import "TestNavigationDelegate.h"
 
+#import <WebKit/WKProcessPoolPrivate.h>
 #import <WebKit/WKWebViewPrivate.h>
 #import <WebKit/WebKit.h>
 
@@ -47,3 +48,20 @@
     auto pid2 = [webView _webProcessIdentifier];
     EXPECT_TRUE(pid != pid2);
 }
+
+TEST(WebKit, TerminateAllProcessesDuringLaunch)
+{
+    auto webView = adoptNS([WKWebView new]);
+
+    // Initiate a load to make sure the process actually launches.
+    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]];
+
+    // Call terminateAllProcesses while the process is still launching.
+    [webView.get().configuration.processPool _terminateAllWebContentProcesses];
+
+    TestWebKitAPI::Util::sleep(0.5);
+
+    // The WKWebView should be able to recover from the WebProcess termination and navigation should succeed.
+    [webView loadHTMLString:@"test" baseURL:nil];
+    [webView _test_waitForDidFinishNavigation];
+}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to