Title: [278913] trunk/Source/WebKit
Revision
278913
Author
cdu...@apple.com
Date
2021-06-15 16:49:26 -0700 (Tue, 15 Jun 2021)

Log Message

Reloading the view should be able to recover if the GPUProcess or NetworkProcess are hung
https://bugs.webkit.org/show_bug.cgi?id=227051

Reviewed by Geoffrey Garen.

Reloading the view should be able to get us out of bad state if the GPUProcess or NetworkProcess are hung.
This is useful as the first instinct of the user may be to reload the page if the page appears hung.

Before the change, if the page is in a bad state due to a hung GPUProcess or NetworkProcess and you'd
reload, the reload would hang indefinitely. After the change, we'll make sure that both processes
are still responsive when triggering the reload. If they are unresponsive, we kill them and the reload
is able to proceed.

* GPUProcess/GPUProcess.cpp:
(WebKit::GPUProcess::didReceiveMessage):
* GPUProcess/GPUProcess.h:
* GPUProcess/GPUProcess.messages.in:
* Shared/AuxiliaryProcess.cpp:
(WebKit::AuxiliaryProcess::mainThreadPing):
* Shared/AuxiliaryProcess.h:
* Shared/AuxiliaryProcess.messages.in:
* UIProcess/AuxiliaryProcessProxy.cpp:
(WebKit::AuxiliaryProcessProxy::checkForResponsiveness):
* UIProcess/AuxiliaryProcessProxy.h:
* UIProcess/GPU/GPUProcessProxy.messages.in:
* UIProcess/Network/NetworkProcessProxy.messages.in:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::reload):
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::isResponsive):
(WebKit::WebProcessProxy::isResponsiveWithLazyStop):
* UIProcess/WebProcessProxy.h:
* UIProcess/WebProcessProxy.messages.in:
* WebProcess/WebProcess.cpp:
* WebProcess/WebProcess.h:
* WebProcess/WebProcess.messages.in:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (278912 => 278913)


--- trunk/Source/WebKit/ChangeLog	2021-06-15 23:31:02 UTC (rev 278912)
+++ trunk/Source/WebKit/ChangeLog	2021-06-15 23:49:26 UTC (rev 278913)
@@ -1,3 +1,42 @@
+2021-06-15  Chris Dumez  <cdu...@apple.com>
+
+        Reloading the view should be able to recover if the GPUProcess or NetworkProcess are hung
+        https://bugs.webkit.org/show_bug.cgi?id=227051
+
+        Reviewed by Geoffrey Garen.
+
+        Reloading the view should be able to get us out of bad state if the GPUProcess or NetworkProcess are hung.
+        This is useful as the first instinct of the user may be to reload the page if the page appears hung.
+
+        Before the change, if the page is in a bad state due to a hung GPUProcess or NetworkProcess and you'd
+        reload, the reload would hang indefinitely. After the change, we'll make sure that both processes
+        are still responsive when triggering the reload. If they are unresponsive, we kill them and the reload
+        is able to proceed.
+
+        * GPUProcess/GPUProcess.cpp:
+        (WebKit::GPUProcess::didReceiveMessage):
+        * GPUProcess/GPUProcess.h:
+        * GPUProcess/GPUProcess.messages.in:
+        * Shared/AuxiliaryProcess.cpp:
+        (WebKit::AuxiliaryProcess::mainThreadPing):
+        * Shared/AuxiliaryProcess.h:
+        * Shared/AuxiliaryProcess.messages.in:
+        * UIProcess/AuxiliaryProcessProxy.cpp:
+        (WebKit::AuxiliaryProcessProxy::checkForResponsiveness):
+        * UIProcess/AuxiliaryProcessProxy.h:
+        * UIProcess/GPU/GPUProcessProxy.messages.in:
+        * UIProcess/Network/NetworkProcessProxy.messages.in:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::reload):
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::isResponsive):
+        (WebKit::WebProcessProxy::isResponsiveWithLazyStop):
+        * UIProcess/WebProcessProxy.h:
+        * UIProcess/WebProcessProxy.messages.in:
+        * WebProcess/WebProcess.cpp:
+        * WebProcess/WebProcess.h:
+        * WebProcess/WebProcess.messages.in:
+
 2021-06-15  Jonathan Bedard  <jbed...@apple.com>
 
         [watchOS 8] Support building WebKit

Modified: trunk/Source/WebKit/GPUProcess/GPUProcess.cpp (278912 => 278913)


--- trunk/Source/WebKit/GPUProcess/GPUProcess.cpp	2021-06-15 23:31:02 UTC (rev 278912)
+++ trunk/Source/WebKit/GPUProcess/GPUProcess.cpp	2021-06-15 23:49:26 UTC (rev 278913)
@@ -91,6 +91,19 @@
 {
 }
 
+void GPUProcess::didReceiveMessage(IPC::Connection& connection, IPC::Decoder& decoder)
+{
+    if (messageReceiverMap().dispatchMessage(connection, decoder))
+        return;
+
+    if (decoder.messageReceiverName() == Messages::AuxiliaryProcess::messageReceiverName()) {
+        AuxiliaryProcess::didReceiveMessage(connection, decoder);
+        return;
+    }
+
+    didReceiveGPUProcessMessage(connection, decoder);
+}
+
 void GPUProcess::createGPUConnectionToWebProcess(ProcessIdentifier identifier, PAL::SessionID sessionID, GPUProcessConnectionParameters&& parameters, CompletionHandler<void(std::optional<IPC::Attachment>&&)>&& completionHandler)
 {
     RELEASE_LOG(Process, "%p - GPUProcess::createGPUConnectionToWebProcess: processIdentifier=%" PRIu64, this, identifier.toUInt64());

Modified: trunk/Source/WebKit/GPUProcess/GPUProcess.h (278912 => 278913)


--- trunk/Source/WebKit/GPUProcess/GPUProcess.h	2021-06-15 23:31:02 UTC (rev 278912)
+++ trunk/Source/WebKit/GPUProcess/GPUProcess.h	2021-06-15 23:49:26 UTC (rev 278913)
@@ -111,6 +111,7 @@
 
     // IPC::Connection::Client
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
+    void didReceiveGPUProcessMessage(IPC::Connection&, IPC::Decoder&);
 
     // Message Handlers
     void initializeGPUProcess(GPUProcessCreationParameters&&);

Modified: trunk/Source/WebKit/GPUProcess/GPUProcess.messages.in (278912 => 278913)


--- trunk/Source/WebKit/GPUProcess/GPUProcess.messages.in	2021-06-15 23:31:02 UTC (rev 278912)
+++ trunk/Source/WebKit/GPUProcess/GPUProcess.messages.in	2021-06-15 23:49:26 UTC (rev 278913)
@@ -22,7 +22,7 @@
 
 #if ENABLE(GPU_PROCESS)
 
-messages -> GPUProcess {
+messages -> GPUProcess LegacyReceiver {
     InitializeGPUProcess(struct WebKit::GPUProcessCreationParameters processCreationParameters)
 
     CreateGPUConnectionToWebProcess(WebCore::ProcessIdentifier processIdentifier, PAL::SessionID sessionID, struct WebKit::GPUProcessConnectionParameters parameters) -> (std::optional<IPC::Attachment> connectionIdentifier) Async

Modified: trunk/Source/WebKit/Shared/AuxiliaryProcess.cpp (278912 => 278913)


--- trunk/Source/WebKit/Shared/AuxiliaryProcess.cpp	2021-06-15 23:31:02 UTC (rev 278912)
+++ trunk/Source/WebKit/Shared/AuxiliaryProcess.cpp	2021-06-15 23:49:26 UTC (rev 278913)
@@ -165,6 +165,11 @@
     m_terminationTimer.startOneShot(m_terminationTimeout);
 }
 
+void AuxiliaryProcess::mainThreadPing(CompletionHandler<void()>&& completionHandler)
+{
+    completionHandler();
+}
+
 IPC::Connection* AuxiliaryProcess::messageSenderConnection() const
 {
     return m_connection.get();

Modified: trunk/Source/WebKit/Shared/AuxiliaryProcess.h (278912 => 278913)


--- trunk/Source/WebKit/Shared/AuxiliaryProcess.h	2021-06-15 23:31:02 UTC (rev 278912)
+++ trunk/Source/WebKit/Shared/AuxiliaryProcess.h	2021-06-15 23:49:26 UTC (rev 278913)
@@ -70,6 +70,7 @@
         removeMessageReceiver(messageReceiverName, destinationID.toUInt64());
     }
 
+    void mainThreadPing(CompletionHandler<void()>&&);
     void setProcessSuppressionEnabled(bool);
 
 #if PLATFORM(COCOA)

Modified: trunk/Source/WebKit/Shared/AuxiliaryProcess.messages.in (278912 => 278913)


--- trunk/Source/WebKit/Shared/AuxiliaryProcess.messages.in	2021-06-15 23:31:02 UTC (rev 278912)
+++ trunk/Source/WebKit/Shared/AuxiliaryProcess.messages.in	2021-06-15 23:49:26 UTC (rev 278913)
@@ -24,6 +24,8 @@
     ShutDown()
     SetProcessSuppressionEnabled(bool flag)
 
+    MainThreadPing() -> () Async
+
 #if OS(LINUX)
     void DidReceiveMemoryPressureEvent(bool isCritical)
 #endif

Modified: trunk/Source/WebKit/UIProcess/AuxiliaryProcessProxy.cpp (278912 => 278913)


--- trunk/Source/WebKit/UIProcess/AuxiliaryProcessProxy.cpp	2021-06-15 23:31:02 UTC (rev 278912)
+++ trunk/Source/WebKit/UIProcess/AuxiliaryProcessProxy.cpp	2021-06-15 23:49:26 UTC (rev 278913)
@@ -375,4 +375,20 @@
     RELEASE_LOG_ERROR(Process, "AuxiliaryProcessProxy::didBecomeUnresponsive: %" PUBLIC_LOG_STRING " process with PID %d became unresponsive", processName().characters(), processIdentifier());
 }
 
+void AuxiliaryProcessProxy::checkForResponsiveness(CompletionHandler<void()>&& responsivenessHandler, UseLazyStop useLazyStop)
+{
+    startResponsivenessTimer(useLazyStop);
+    sendWithAsyncReply(Messages::AuxiliaryProcess::MainThreadPing(), [weakThis = makeWeakPtr(*this), responsivenessHandler = WTFMove(responsivenessHandler)]() mutable {
+        // Schedule an asynchronous task because our completion handler may have been called as a result of the AuxiliaryProcessProxy
+        // being in the middle of destruction.
+        RunLoop::main().dispatch([weakThis = WTFMove(weakThis), responsivenessHandler = WTFMove(responsivenessHandler)]() mutable {
+            if (weakThis)
+                weakThis->stopResponsivenessTimer();
+
+            if (responsivenessHandler)
+                responsivenessHandler();
+        });
+    });
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit/UIProcess/AuxiliaryProcessProxy.h (278912 => 278913)


--- trunk/Source/WebKit/UIProcess/AuxiliaryProcessProxy.h	2021-06-15 23:31:02 UTC (rev 278912)
+++ trunk/Source/WebKit/UIProcess/AuxiliaryProcessProxy.h	2021-06-15 23:49:26 UTC (rev 278913)
@@ -132,6 +132,8 @@
     void startResponsivenessTimer(UseLazyStop = UseLazyStop::No);
     void stopResponsivenessTimer();
 
+    void checkForResponsiveness(CompletionHandler<void()>&& = nullptr, UseLazyStop = UseLazyStop::No);
+
     ResponsivenessTimer& responsivenessTimer() { return m_responsivenessTimer; }
     const ResponsivenessTimer& responsivenessTimer() const { return m_responsivenessTimer; }
 

Modified: trunk/Source/WebKit/UIProcess/GPU/GPUProcessProxy.messages.in (278912 => 278913)


--- trunk/Source/WebKit/UIProcess/GPU/GPUProcessProxy.messages.in	2021-06-15 23:31:02 UTC (rev 278912)
+++ trunk/Source/WebKit/UIProcess/GPU/GPUProcessProxy.messages.in	2021-06-15 23:49:26 UTC (rev 278913)
@@ -22,7 +22,7 @@
 
 #if ENABLE(GPU_PROCESS)
 
-messages -> GPUProcessProxy NotRefCounted {
+messages -> GPUProcessProxy {
 
 #if HAVE(VISIBILITY_PROPAGATION_VIEW)
     DidCreateContextForVisibilityPropagation(WebKit::WebPageProxyIdentifier pageProxyID, WebCore::PageIdentifier pageID, WebKit::LayerHostingContextID contextID)

Modified: trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.messages.in (278912 => 278913)


--- trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.messages.in	2021-06-15 23:31:02 UTC (rev 278912)
+++ trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.messages.in	2021-06-15 23:49:26 UTC (rev 278913)
@@ -20,7 +20,7 @@
 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-messages -> NetworkProcessProxy LegacyReceiver NotRefCounted {
+messages -> NetworkProcessProxy LegacyReceiver {
     DidReceiveAuthenticationChallenge(PAL::SessionID sessionID, WebKit::WebPageProxyIdentifier pageID, std::optional<WebCore::SecurityOriginData> topOrigin, WebCore::AuthenticationChallenge challenge, bool negotiatedLegacyTLS, uint64_t challengeID)
     NegotiatedLegacyTLS(WebKit::WebPageProxyIdentifier pageID)
     DidNegotiateModernTLS(WebKit::WebPageProxyIdentifier pageID, URL url)

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (278912 => 278913)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-06-15 23:31:02 UTC (rev 278912)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-06-15 23:49:26 UTC (rev 278913)
@@ -1650,6 +1650,14 @@
 {
     WEBPAGEPROXY_RELEASE_LOG(Loading, "reload:");
 
+    // Make sure the Network & GPU processes are still responsive. This is so that reload() gets us out of the bad state if one of these
+    // processes is hung.
+    websiteDataStore().networkProcess().checkForResponsiveness();
+#if ENABLE(GPU_PROCESS)
+    if (auto* gpuProcess = process().processPool().gpuProcess())
+        gpuProcess->checkForResponsiveness();
+#endif
+
     SandboxExtension::Handle sandboxExtensionHandle;
 
     String url = ""

Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp (278912 => 278913)


--- trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp	2021-06-15 23:31:02 UTC (rev 278912)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp	2021-06-15 23:49:26 UTC (rev 278913)
@@ -1477,8 +1477,13 @@
     if (callback)
         m_isResponsiveCallbacks.append(WTFMove(callback));
 
-    startResponsivenessTimer();
-    send(Messages::WebProcess::MainThreadPing(), 0);
+    checkForResponsiveness([weakThis = makeWeakPtr(*this)]() mutable {
+        if (!weakThis)
+            return;
+
+        for (auto& isResponsive : std::exchange(weakThis->m_isResponsiveCallbacks, { }))
+            isResponsive(true);
+    });
 }
 
 void WebProcessProxy::isResponsiveWithLazyStop()
@@ -1489,8 +1494,13 @@
     if (!responsivenessTimer().hasActiveTimer()) {
         // We do not send a ping if we are already waiting for the WebProcess.
         // Spamming pings on a slow web process is not helpful.
-        responsivenessTimer().startWithLazyStop();
-        send(Messages::WebProcess::MainThreadPing(), 0);
+        checkForResponsiveness([weakThis = makeWeakPtr(*this)]() mutable {
+            if (!weakThis)
+                return;
+
+            for (auto& isResponsive : std::exchange(weakThis->m_isResponsiveCallbacks, { }))
+                isResponsive(true);
+        }, UseLazyStop::Yes);
     }
 }
 
@@ -1504,16 +1514,6 @@
     return processPool().configuration().isJITEnabled();
 }
 
-void WebProcessProxy::didReceiveMainThreadPing()
-{
-    responsivenessTimer().stop();
-
-    auto isResponsiveCallbacks = WTFMove(m_isResponsiveCallbacks);
-    bool isWebProcessResponsive = true;
-    for (auto& callback : isResponsiveCallbacks)
-        callback(isWebProcessResponsive);
-}
-
 void WebProcessProxy::didReceiveBackgroundResponsivenessPing()
 {
     m_backgroundResponsivenessTimer.didReceiveBackgroundResponsivenessPong();

Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.h (278912 => 278913)


--- trunk/Source/WebKit/UIProcess/WebProcessProxy.h	2021-06-15 23:31:02 UTC (rev 278912)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.h	2021-06-15 23:49:26 UTC (rev 278913)
@@ -259,7 +259,6 @@
 
     void isResponsive(CompletionHandler<void(bool isWebProcessResponsive)>&&);
     void isResponsiveWithLazyStop();
-    void didReceiveMainThreadPing();
     void didReceiveBackgroundResponsivenessPing();
 
     void memoryPressureStatusChanged(bool isUnderMemoryPressure) { m_isUnderMemoryPressure = isUnderMemoryPressure; }

Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.messages.in (278912 => 278913)


--- trunk/Source/WebKit/UIProcess/WebProcessProxy.messages.in	2021-06-15 23:31:02 UTC (rev 278912)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.messages.in	2021-06-15 23:49:26 UTC (rev 278913)
@@ -53,8 +53,6 @@
     DidExceedCPULimit()
 
     StopResponsivenessTimer()
-
-    DidReceiveMainThreadPing()
     DidReceiveBackgroundResponsivenessPing()
 
     MemoryPressureStatusChanged(bool isUnderMemoryPressure)

Modified: trunk/Source/WebKit/WebProcess/WebProcess.cpp (278912 => 278913)


--- trunk/Source/WebKit/WebProcess/WebProcess.cpp	2021-06-15 23:31:02 UTC (rev 278912)
+++ trunk/Source/WebKit/WebProcess/WebProcess.cpp	2021-06-15 23:49:26 UTC (rev 278913)
@@ -970,11 +970,6 @@
     GCController::singleton().garbageCollectNow();
 }
 
-void WebProcess::mainThreadPing()
-{
-    parentProcessConnection()->send(Messages::WebProcessProxy::DidReceiveMainThreadPing(), 0);
-}
-
 void WebProcess::backgroundResponsivenessPing()
 {
     parentProcessConnection()->send(Messages::WebProcessProxy::DidReceiveBackgroundResponsivenessPing(), 0);

Modified: trunk/Source/WebKit/WebProcess/WebProcess.h (278912 => 278913)


--- trunk/Source/WebKit/WebProcess/WebProcess.h	2021-06-15 23:31:02 UTC (rev 278912)
+++ trunk/Source/WebKit/WebProcess/WebProcess.h	2021-06-15 23:49:26 UTC (rev 278913)
@@ -455,7 +455,6 @@
     void garbageCollectJavaScriptObjects();
     void setJavaScriptGarbageCollectorTimerEnabled(bool flag);
 
-    void mainThreadPing();
     void backgroundResponsivenessPing();
 
 #if ENABLE(GAMEPAD)

Modified: trunk/Source/WebKit/WebProcess/WebProcess.messages.in (278912 => 278913)


--- trunk/Source/WebKit/WebProcess/WebProcess.messages.in	2021-06-15 23:31:02 UTC (rev 278912)
+++ trunk/Source/WebKit/WebProcess/WebProcess.messages.in	2021-06-15 23:49:26 UTC (rev 278913)
@@ -92,7 +92,6 @@
     PrepareToSuspend(bool isSuspensionImminent) -> () Async
     ProcessDidResume()
 
-    MainThreadPing()
     BackgroundResponsivenessPing()
 
 #if ENABLE(GAMEPAD)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to