Title: [290196] trunk
Revision
290196
Author
sihui_...@apple.com
Date
2022-02-18 20:14:04 -0800 (Fri, 18 Feb 2022)

Log Message

Source/WebKit:
Add assertion that no two network sessions share the same storage path
https://bugs.webkit.org/show_bug.cgi?id=236844

Reviewed by Chris Dumez.

Each NetworkStorageManager has its own queue and accesses the storage files on that queue, so we can't have two
NetworkworkStorageManagers use the same path, as the path may be accessed concurrently and cause corruption.
Currently we have an SPI for setting custom generalStorageDirectory for WebsiteDataStore (in
_WKWebsiteDataStoreConfiguration), which means SPI clients can create two sessions with the same path in theory.
Let's add an assertion to ensure that does not happen.

This assertion has helped find a bug in WebKitTestRunner that we didn't set custom generalStorageDirectory for a
custom WebsiteDataStore (so it's using the same path as default WebsiteDataStore).

* NetworkProcess/storage/NetworkStorageManager.cpp:
(WebKit::activePaths):
(WebKit::NetworkStorageManager::NetworkStorageManager):
(WebKit::NetworkStorageManager::~NetworkStorageManager):

Tools:
Add assertion that no two network session share the same storage path
https://bugs.webkit.org/show_bug.cgi?id=236844

Reviewed by Chris Dumez.

* WebKitTestRunner/TestController.cpp:
(WTR::TestController::configureWebsiteDataStoreTemporaryDirectories):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (290195 => 290196)


--- trunk/Source/WebKit/ChangeLog	2022-02-19 03:56:45 UTC (rev 290195)
+++ trunk/Source/WebKit/ChangeLog	2022-02-19 04:14:04 UTC (rev 290196)
@@ -1,3 +1,24 @@
+2022-02-18  Sihui Liu  <sihui_...@apple.com>
+
+        Add assertion that no two network sessions share the same storage path
+        https://bugs.webkit.org/show_bug.cgi?id=236844
+
+        Reviewed by Chris Dumez.
+
+        Each NetworkStorageManager has its own queue and accesses the storage files on that queue, so we can't have two
+        NetworkworkStorageManagers use the same path, as the path may be accessed concurrently and cause corruption. 
+        Currently we have an SPI for setting custom generalStorageDirectory for WebsiteDataStore (in 
+        _WKWebsiteDataStoreConfiguration), which means SPI clients can create two sessions with the same path in theory.
+        Let's add an assertion to ensure that does not happen.
+
+        This assertion has helped find a bug in WebKitTestRunner that we didn't set custom generalStorageDirectory for a
+        custom WebsiteDataStore (so it's using the same path as default WebsiteDataStore).
+
+        * NetworkProcess/storage/NetworkStorageManager.cpp:
+        (WebKit::activePaths):
+        (WebKit::NetworkStorageManager::NetworkStorageManager):
+        (WebKit::NetworkStorageManager::~NetworkStorageManager):
+
 2022-02-18  Per Arne Vollan  <pvol...@apple.com>
 
         Move content filtering to Networking process

Modified: trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp (290195 => 290196)


--- trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp	2022-02-19 03:56:45 UTC (rev 290195)
+++ trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp	2022-02-19 04:14:04 UTC (rev 290196)
@@ -108,6 +108,12 @@
         FileSystem::deleteFile(filePath);
 }
 
+static HashSet<String>& activePaths()
+{
+    static MainThreadNeverDestroyed<HashSet<String>> paths;
+    return paths;
+}
+
 Ref<NetworkStorageManager> NetworkStorageManager::create(PAL::SessionID sessionID, IPC::Connection::UniqueID connection, const String& path, const String& customLocalStoragePath, const String& customIDBStoragePath, const String& customCacheStoragePath, uint64_t defaultOriginQuota, uint64_t defaultThirdPartyOriginQuota, bool shouldUseCustomPaths)
 {
     return adoptRef(*new NetworkStorageManager(sessionID, connection, path, customLocalStoragePath, customIDBStoragePath, customCacheStoragePath, defaultOriginQuota, defaultThirdPartyOriginQuota, shouldUseCustomPaths));
@@ -122,6 +128,12 @@
 {
     ASSERT(RunLoop::isMain());
 
+    // Sessions are not supposed to share the same path, as each session runs on its own queue
+    // and this can cause corruption. If the assertion is hit, check if you create multiple
+    // WebsiteDataStores with the same generalStorageDirectory.
+    if (!path.isEmpty())
+        RELEASE_ASSERT(activePaths().add(path).isNewEntry);
+
     m_queue->dispatch([this, protectedThis = Ref { *this }, path = path.isolatedCopy(), customLocalStoragePath = crossThreadCopy(customLocalStoragePath), customIDBStoragePath = crossThreadCopy(customIDBStoragePath), customCacheStoragePath = crossThreadCopy(customCacheStoragePath), shouldUseCustomPaths]() mutable {
         m_fileSystemStorageHandleRegistry = makeUnique<FileSystemStorageHandleRegistry>();
         m_storageAreaRegistry = makeUnique<StorageAreaRegistry>();
@@ -142,6 +154,9 @@
 {
     ASSERT(RunLoop::isMain());
     ASSERT(m_closed);
+
+    if (!m_path.isEmpty())
+        activePaths().remove(m_path);
 }
 
 bool NetworkStorageManager::canHandleTypes(OptionSet<WebsiteDataType> types)

Modified: trunk/Tools/ChangeLog (290195 => 290196)


--- trunk/Tools/ChangeLog	2022-02-19 03:56:45 UTC (rev 290195)
+++ trunk/Tools/ChangeLog	2022-02-19 04:14:04 UTC (rev 290196)
@@ -1,3 +1,13 @@
+2022-02-18  Sihui Liu  <sihui_...@apple.com>
+
+        Add assertion that no two network session share the same storage path
+        https://bugs.webkit.org/show_bug.cgi?id=236844
+
+        Reviewed by Chris Dumez.
+
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::TestController::configureWebsiteDataStoreTemporaryDirectories):
+
 2022-02-18  Angelos Oikonomopoulos  <ange...@igalia.com>
 
         [JSC] Fix test sharding when using --make-runner and --remote

Modified: trunk/Tools/WebKitTestRunner/TestController.cpp (290195 => 290196)


--- trunk/Tools/WebKitTestRunner/TestController.cpp	2022-02-19 03:56:45 UTC (rev 290195)
+++ trunk/Tools/WebKitTestRunner/TestController.cpp	2022-02-19 04:14:04 UTC (rev 290196)
@@ -614,6 +614,7 @@
         WKWebsiteDataStoreConfigurationSetMediaKeysStorageDirectory(configuration, toWK(makeString(temporaryFolder, pathSeparator, "MediaKeys", pathSeparator, randomNumber)).get());
         WKWebsiteDataStoreConfigurationSetResourceLoadStatisticsDirectory(configuration, toWK(makeString(temporaryFolder, pathSeparator, "ResourceLoadStatistics", pathSeparator, randomNumber)).get());
         WKWebsiteDataStoreConfigurationSetServiceWorkerRegistrationDirectory(configuration, toWK(makeString(temporaryFolder, pathSeparator, "ServiceWorkers", pathSeparator, randomNumber)).get());
+        WKWebsiteDataStoreConfigurationSetGeneralStorageDirectory(configuration, toWK(makeString(temporaryFolder, pathSeparator, "Default", pathSeparator, randomNumber)).get());
 #if PLATFORM(WIN)
         WKWebsiteDataStoreConfigurationSetCookieStorageFile(configuration, toWK(makeString(temporaryFolder, pathSeparator, "cookies", pathSeparator, randomNumber, pathSeparator, "cookiejar.db")).get());
 #endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to