Title: [276401] branches/safari-611-branch
Revision
276401
Author
[email protected]
Date
2021-04-21 16:39:17 -0700 (Wed, 21 Apr 2021)

Log Message

Cherry-pick r275487. rdar://problem/76962948

    REGRESSION(r267763) NetworkProcess never terminates
    https://bugs.webkit.org/show_bug.cgi?id=224191
    <rdar://problem/76124590>

    Patch by Alex Christensen <[email protected]> on 2021-04-05
    Reviewed by Chris Dumez.

    Source/WebKit:

    Before r267763, when a WebProcessPool was deallocated, the NetworkProcess it owned was terminated.
    Since then, once you start using a NetworkProcess, it will be kept until your app closes or it crashes.
    To reclaim these resources in a way similar to how we did before, we now terminate the network process in two situations:
    1. If all WebsiteDataStores associated with it are deallocated.  This happens if you have never used the default WKWebsiteDataStore.
    2. If all WebProcessPools are deallocated.  This can still happen if you do use the default WKWebsiteDataStore, which is never deallocated.

    Covered by API tests.

    * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
    (+[WKWebsiteDataStore _defaultNetworkProcessExists]):
    * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
    * UIProcess/Network/NetworkProcessProxy.cpp:
    (WebKit::NetworkProcessProxy::defaultNetworkProcessExists):
    (WebKit::NetworkProcessProxy::removeSession):
    * UIProcess/Network/NetworkProcessProxy.h:
    * UIProcess/WebProcessPool.cpp:
    (WebKit::WebProcessPool::~WebProcessPool):

    Tools:

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

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

Modified Paths

Diff

Modified: branches/safari-611-branch/Source/WebKit/ChangeLog (276400 => 276401)


--- branches/safari-611-branch/Source/WebKit/ChangeLog	2021-04-21 23:39:13 UTC (rev 276400)
+++ branches/safari-611-branch/Source/WebKit/ChangeLog	2021-04-21 23:39:17 UTC (rev 276401)
@@ -1,5 +1,69 @@
 2021-04-21  Ruben Turcios  <[email protected]>
 
+        Cherry-pick r275487. rdar://problem/76962948
+
+    REGRESSION(r267763) NetworkProcess never terminates
+    https://bugs.webkit.org/show_bug.cgi?id=224191
+    <rdar://problem/76124590>
+    
+    Patch by Alex Christensen <[email protected]> on 2021-04-05
+    Reviewed by Chris Dumez.
+    
+    Source/WebKit:
+    
+    Before r267763, when a WebProcessPool was deallocated, the NetworkProcess it owned was terminated.
+    Since then, once you start using a NetworkProcess, it will be kept until your app closes or it crashes.
+    To reclaim these resources in a way similar to how we did before, we now terminate the network process in two situations:
+    1. If all WebsiteDataStores associated with it are deallocated.  This happens if you have never used the default WKWebsiteDataStore.
+    2. If all WebProcessPools are deallocated.  This can still happen if you do use the default WKWebsiteDataStore, which is never deallocated.
+    
+    Covered by API tests.
+    
+    * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
+    (+[WKWebsiteDataStore _defaultNetworkProcessExists]):
+    * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
+    * UIProcess/Network/NetworkProcessProxy.cpp:
+    (WebKit::NetworkProcessProxy::defaultNetworkProcessExists):
+    (WebKit::NetworkProcessProxy::removeSession):
+    * UIProcess/Network/NetworkProcessProxy.h:
+    * UIProcess/WebProcessPool.cpp:
+    (WebKit::WebProcessPool::~WebProcessPool):
+    
+    Tools:
+    
+    * TestWebKitAPI/Tests/WebKitCocoa/NetworkProcess.mm:
+    (TEST):
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@275487 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-04-05  Alex Christensen  <[email protected]>
+
+            REGRESSION(r267763) NetworkProcess never terminates
+            https://bugs.webkit.org/show_bug.cgi?id=224191
+            <rdar://problem/76124590>
+
+            Reviewed by Chris Dumez.
+
+            Before r267763, when a WebProcessPool was deallocated, the NetworkProcess it owned was terminated.
+            Since then, once you start using a NetworkProcess, it will be kept until your app closes or it crashes.
+            To reclaim these resources in a way similar to how we did before, we now terminate the network process in two situations:
+            1. If all WebsiteDataStores associated with it are deallocated.  This happens if you have never used the default WKWebsiteDataStore.
+            2. If all WebProcessPools are deallocated.  This can still happen if you do use the default WKWebsiteDataStore, which is never deallocated.
+
+            Covered by API tests.
+
+            * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
+            (+[WKWebsiteDataStore _defaultNetworkProcessExists]):
+            * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
+            * UIProcess/Network/NetworkProcessProxy.cpp:
+            (WebKit::NetworkProcessProxy::defaultNetworkProcessExists):
+            (WebKit::NetworkProcessProxy::removeSession):
+            * UIProcess/Network/NetworkProcessProxy.h:
+            * UIProcess/WebProcessPool.cpp:
+            (WebKit::WebProcessPool::~WebProcessPool):
+
+2021-04-21  Ruben Turcios  <[email protected]>
+
         Cherry-pick r274504. rdar://problem/76962959
 
     The WebContent process crashes when launching Safari

Modified: branches/safari-611-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm (276400 => 276401)


--- branches/safari-611-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm	2021-04-21 23:39:13 UTC (rev 276400)
+++ branches/safari-611-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm	2021-04-21 23:39:17 UTC (rev 276401)
@@ -29,6 +29,7 @@
 #import "APIString.h"
 #import "AuthenticationChallengeDispositionCocoa.h"
 #import "CompletionHandlerCallChecker.h"
+#import "NetworkProcessProxy.h"
 #import "ShouldGrandfatherStatistics.h"
 #import "WKHTTPCookieStoreInternal.h"
 #import "WKNSArray.h"
@@ -705,4 +706,9 @@
     return !!_websiteDataStore->networkProcessIfExists();
 }
 
++ (BOOL)_defaultNetworkProcessExists
+{
+    return !!WebKit::NetworkProcessProxy::defaultNetworkProcess();
+}
+
 @end

Modified: branches/safari-611-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h (276400 => 276401)


--- branches/safari-611-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h	2021-04-21 23:39:13 UTC (rev 276400)
+++ branches/safari-611-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h	2021-04-21 23:39:17 UTC (rev 276401)
@@ -97,6 +97,7 @@
 - (pid_t)_networkProcessIdentifier WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 + (void)_makeNextNetworkProcessLaunchFailForTesting WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 - (BOOL)_networkProcessExists WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
++ (BOOL)_defaultNetworkProcessExists WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 @end
 

Modified: branches/safari-611-branch/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp (276400 => 276401)


--- branches/safari-611-branch/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp	2021-04-21 23:39:13 UTC (rev 276400)
+++ branches/safari-611-branch/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp	2021-04-21 23:39:17 UTC (rev 276401)
@@ -101,17 +101,17 @@
     return processes;
 }
 
-static RefPtr<NetworkProcessProxy>& defaultProcess()
+RefPtr<NetworkProcessProxy>& NetworkProcessProxy::defaultNetworkProcess()
 {
     static NeverDestroyed<RefPtr<NetworkProcessProxy>> process;
     return process.get();
 }
 
-Ref<NetworkProcessProxy> NetworkProcessProxy::defaultNetworkProcess()
+Ref<NetworkProcessProxy> NetworkProcessProxy::ensureDefaultNetworkProcess()
 {
-    if (!defaultProcess())
-        defaultProcess() = NetworkProcessProxy::create();
-    return *defaultProcess();
+    if (!defaultNetworkProcess())
+        defaultNetworkProcess() = NetworkProcessProxy::create();
+    return *defaultNetworkProcess();
 }
 
 void NetworkProcessProxy::terminate()
@@ -340,8 +340,8 @@
 
 void NetworkProcessProxy::networkProcessCrashed()
 {
-    if (defaultProcess() == this)
-        defaultProcess() = nullptr;
+    if (defaultNetworkProcess() == this)
+        defaultNetworkProcess() = nullptr;
 
     clearCallbackStates();
 
@@ -1350,6 +1350,9 @@
 
     if (canSendMessage())
         send(Messages::NetworkProcess::DestroySession { websiteDataStore.sessionID() }, 0);
+
+    if (m_websiteDataStores.computesEmpty())
+        defaultNetworkProcess() = nullptr;
 }
 
 WebsiteDataStore* NetworkProcessProxy::websiteDataStoreFromSessionID(PAL::SessionID sessionID)

Modified: branches/safari-611-branch/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h (276400 => 276401)


--- branches/safari-611-branch/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h	2021-04-21 23:39:13 UTC (rev 276400)
+++ branches/safari-611-branch/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h	2021-04-21 23:39:17 UTC (rev 276401)
@@ -108,7 +108,8 @@
     using DomainInNeedOfStorageAccess = WebCore::RegistrableDomain;
     using OpenerDomain = WebCore::RegistrableDomain;
 
-    static Ref<NetworkProcessProxy> defaultNetworkProcess();
+    static Ref<NetworkProcessProxy> ensureDefaultNetworkProcess();
+    static RefPtr<NetworkProcessProxy>& defaultNetworkProcess();
     static Ref<NetworkProcessProxy> create() { return adoptRef(*new NetworkProcessProxy); }
     ~NetworkProcessProxy();
 

Modified: branches/safari-611-branch/Source/WebKit/UIProcess/WebProcessPool.cpp (276400 => 276401)


--- branches/safari-611-branch/Source/WebKit/UIProcess/WebProcessPool.cpp	2021-04-21 23:39:13 UTC (rev 276400)
+++ branches/safari-611-branch/Source/WebKit/UIProcess/WebProcessPool.cpp	2021-04-21 23:39:17 UTC (rev 276401)
@@ -375,6 +375,9 @@
 
         process->shutDown();
     }
+
+    if (processPools().isEmpty() && !!NetworkProcessProxy::defaultNetworkProcess())
+        NetworkProcessProxy::defaultNetworkProcess() = nullptr;
 }
 
 void WebProcessPool::initializeClient(const WKContextClientBase* client)

Modified: branches/safari-611-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp (276400 => 276401)


--- branches/safari-611-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2021-04-21 23:39:13 UTC (rev 276400)
+++ branches/safari-611-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2021-04-21 23:39:17 UTC (rev 276401)
@@ -200,7 +200,7 @@
     return NetworkProcessProxy::create();
 #else
     UNUSED_PARAM(sessionID);
-    return NetworkProcessProxy::defaultNetworkProcess();
+    return NetworkProcessProxy::ensureDefaultNetworkProcess();
 #endif
 }
 

Modified: branches/safari-611-branch/Tools/ChangeLog (276400 => 276401)


--- branches/safari-611-branch/Tools/ChangeLog	2021-04-21 23:39:13 UTC (rev 276400)
+++ branches/safari-611-branch/Tools/ChangeLog	2021-04-21 23:39:17 UTC (rev 276401)
@@ -1,3 +1,52 @@
+2021-04-21  Ruben Turcios  <[email protected]>
+
+        Cherry-pick r275487. rdar://problem/76962948
+
+    REGRESSION(r267763) NetworkProcess never terminates
+    https://bugs.webkit.org/show_bug.cgi?id=224191
+    <rdar://problem/76124590>
+    
+    Patch by Alex Christensen <[email protected]> on 2021-04-05
+    Reviewed by Chris Dumez.
+    
+    Source/WebKit:
+    
+    Before r267763, when a WebProcessPool was deallocated, the NetworkProcess it owned was terminated.
+    Since then, once you start using a NetworkProcess, it will be kept until your app closes or it crashes.
+    To reclaim these resources in a way similar to how we did before, we now terminate the network process in two situations:
+    1. If all WebsiteDataStores associated with it are deallocated.  This happens if you have never used the default WKWebsiteDataStore.
+    2. If all WebProcessPools are deallocated.  This can still happen if you do use the default WKWebsiteDataStore, which is never deallocated.
+    
+    Covered by API tests.
+    
+    * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
+    (+[WKWebsiteDataStore _defaultNetworkProcessExists]):
+    * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
+    * UIProcess/Network/NetworkProcessProxy.cpp:
+    (WebKit::NetworkProcessProxy::defaultNetworkProcessExists):
+    (WebKit::NetworkProcessProxy::removeSession):
+    * UIProcess/Network/NetworkProcessProxy.h:
+    * UIProcess/WebProcessPool.cpp:
+    (WebKit::WebProcessPool::~WebProcessPool):
+    
+    Tools:
+    
+    * TestWebKitAPI/Tests/WebKitCocoa/NetworkProcess.mm:
+    (TEST):
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@275487 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-04-05  Alex Christensen  <[email protected]>
+
+            REGRESSION(r267763) NetworkProcess never terminates
+            https://bugs.webkit.org/show_bug.cgi?id=224191
+            <rdar://problem/76124590>
+
+            Reviewed by Chris Dumez.
+
+            * TestWebKitAPI/Tests/WebKitCocoa/NetworkProcess.mm:
+            (TEST):
+
 2021-04-16  Russell Epstein  <[email protected]>
 
         Cherry-pick r274565. rdar://problem/76412930

Modified: branches/safari-611-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/NetworkProcess.mm (276400 => 276401)


--- branches/safari-611-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/NetworkProcess.mm	2021-04-21 23:39:13 UTC (rev 276400)
+++ branches/safari-611-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/NetworkProcess.mm	2021-04-21 23:39:17 UTC (rev 276401)
@@ -33,7 +33,7 @@
 #import <wtf/RetainPtr.h>
 #import <wtf/Vector.h>
 
-TEST(WebKit, NetworkProcessEntitlements)
+TEST(NetworkProcess, Entitlements)
 {
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:[[[WKWebViewConfiguration alloc] init] autorelease]]);
     [webView synchronouslyLoadTestPageNamed:@"simple"];
@@ -79,9 +79,34 @@
     checkReferer([NSURL URLWithString:shorterHost], shorterHost.UTF8String);
 }
 
-TEST(WebKit, NetworkProcessLaunchOnlyWhenNecessary)
+TEST(NetworkProcess, LaunchOnlyWhenNecessary)
 {
     auto webView = [[WKWebView new] autorelease];
     webView.configuration.websiteDataStore._resourceLoadStatisticsEnabled = YES;
     EXPECT_FALSE([webView.configuration.websiteDataStore _networkProcessExists]);
 }
+
+TEST(NetworkProcess, TerminateWhenUnused)
+{
+    RetainPtr<WKProcessPool> retainedPool;
+    @autoreleasepool {
+        auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+        configuration.get().websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore];
+        retainedPool = configuration.get().processPool;
+        auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 0, 0) configuration:configuration.get()]);
+        [webView synchronouslyLoadTestPageNamed:@"simple"];
+        EXPECT_TRUE([WKWebsiteDataStore _defaultNetworkProcessExists]);
+    }
+    while ([WKWebsiteDataStore _defaultNetworkProcessExists])
+        TestWebKitAPI::Util::spinRunLoop();
+    
+    retainedPool = nil;
+    
+    @autoreleasepool {
+        auto webView = adoptNS([WKWebView new]);
+        [webView synchronouslyLoadTestPageNamed:@"simple"];
+        EXPECT_TRUE([WKWebsiteDataStore _defaultNetworkProcessExists]);
+    }
+    while ([WKWebsiteDataStore _defaultNetworkProcessExists])
+        TestWebKitAPI::Util::spinRunLoop();
+}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to