Unresponsive Service Worker processes should get killed
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 May 2019 23:23:55 +0000 (23:23 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 May 2019 23:23:55 +0000 (23:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=197580
<rdar://problem/50458239>

Reviewed by Geoffrey Garen.

Enable the background responsiveness logic for service worker processes so that they get
killed if they becomes unresponsive. The logic was previously not enabling the timer for
service worker processes because it required having a page.

* UIProcess/BackgroundProcessResponsivenessTimer.cpp:
(WebKit::BackgroundProcessResponsivenessTimer::shouldBeActive const):
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::didBecomeUnresponsive):
(WebKit::WebProcessProxy::didFinishLaunching):

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/BackgroundProcessResponsivenessTimer.cpp
Source/WebKit/UIProcess/WebProcessProxy.cpp

index 2b42ad7..dce1b4f 100644 (file)
@@ -1,3 +1,21 @@
+2019-05-03  Chris Dumez  <cdumez@apple.com>
+
+        Unresponsive Service Worker processes should get killed
+        https://bugs.webkit.org/show_bug.cgi?id=197580
+        <rdar://problem/50458239>
+
+        Reviewed by Geoffrey Garen.
+
+        Enable the background responsiveness logic for service worker processes so that they get
+        killed if they becomes unresponsive. The logic was previously not enabling the timer for
+        service worker processes because it required having a page.
+
+        * UIProcess/BackgroundProcessResponsivenessTimer.cpp:
+        (WebKit::BackgroundProcessResponsivenessTimer::shouldBeActive const):
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::didBecomeUnresponsive):
+        (WebKit::WebProcessProxy::didFinishLaunching):
+
 2019-05-03  Youenn Fablet  <youenn@apple.com>
 
         [iOS] set the default maximum camera count to 1 for enumerateDevices
index ea4d9d7..548a8bb 100644 (file)
@@ -132,6 +132,9 @@ void BackgroundProcessResponsivenessTimer::setResponsive(bool isResponsive)
 bool BackgroundProcessResponsivenessTimer::shouldBeActive() const
 {
 #if !PLATFORM(IOS_FAMILY)
+    // Service worker process are always in the background.
+    if (m_webProcessProxy.isServiceWorkerProcess())
+        return true;
     return !m_webProcessProxy.visiblePageCount() && m_webProcessProxy.pageCount();
 #else
     // Disable background process responsiveness checking on iOS since such processes usually get suspended.
index c37208d..d4f37d7 100644 (file)
@@ -723,6 +723,12 @@ void WebProcessProxy::didBecomeUnresponsive()
     bool isWebProcessResponsive = false;
     for (auto& callback : isResponsiveCallbacks)
         callback(isWebProcessResponsive);
+
+    // If the service worker process becomes unresponsive, kill it ourselves since there are no native clients to do it.
+    if (isServiceWorkerProcess()) {
+        RELEASE_LOG_ERROR(PerformanceLogging, "%p - WebProcessProxy::didBecomeUnresponsive() Terminating Service Worker process with pid %d because it is unresponsive", this, processIdentifier());
+        terminate();
+    }
 }
 
 void WebProcessProxy::didBecomeResponsive()
@@ -766,6 +772,7 @@ void WebProcessProxy::didFinishLaunching(ProcessLauncher* launcher, IPC::Connect
     m_webConnection = WebConnectionToWebProcess::create(this);
 
     m_processPool->processDidFinishLaunching(this);
+    m_backgroundResponsivenessTimer.updateState();
 
     for (auto* visitedLinkStore : m_visitedLinkStoresWithUsers.keys())
         visitedLinkStore->addProcess(*this);