Title: [262505] trunk/Source
Revision
262505
Author
katherine_che...@apple.com
Date
2020-06-03 12:13:26 -0700 (Wed, 03 Jun 2020)

Log Message

Any active sqlite transactions for the ITP database should be aborted when the network process suspends.
https://bugs.webkit.org/show_bug.cgi?id=212608
<rdar://problem/60540768>

Reviewed by Chris Dumez.

Source/WebCore:

Add WEBCORE_EXPORT macro to use interrupt() function in
ResourceLoadStatisticsDatabaseStore.

* platform/sql/SQLiteDatabase.h:

Source/WebKit:

Calls to WebResourceLoadStatisticsStore::suspend() should abort any
active SQLite transactions. Unfinished transactions will hold the lock
of a database file and could cause the network process to crash when
suspending.

* NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp:
(WebKit::ResourceLoadStatisticsDatabaseStore::ResourceLoadStatisticsDatabaseStore):
(WebKit::ResourceLoadStatisticsDatabaseStore::~ResourceLoadStatisticsDatabaseStore):
Store all ResourceLoadStatisticsDatabaseStore instances in a static
HashSet so existing transactions can be aborted when the process is
preparing to suspend.

(WebKit::ResourceLoadStatisticsDatabaseStore::interrupt):
* NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h:
* NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:
(WebKit::WebResourceLoadStatisticsStore::suspend):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (262504 => 262505)


--- trunk/Source/WebCore/ChangeLog	2020-06-03 19:13:04 UTC (rev 262504)
+++ trunk/Source/WebCore/ChangeLog	2020-06-03 19:13:26 UTC (rev 262505)
@@ -1,3 +1,16 @@
+2020-06-03  Kate Cheney  <katherine_che...@apple.com>
+
+        Any active sqlite transactions for the ITP database should be aborted when the network process suspends.
+        https://bugs.webkit.org/show_bug.cgi?id=212608
+        <rdar://problem/60540768>
+
+        Reviewed by Chris Dumez.
+
+        Add WEBCORE_EXPORT macro to use interrupt() function in
+        ResourceLoadStatisticsDatabaseStore.
+
+        * platform/sql/SQLiteDatabase.h:
+
 2020-06-03  Andres Gonzalez  <andresg...@apple.com>
 
         AX: SVG text node with content is described as "empty group" even if it's not empty

Modified: trunk/Source/WebCore/platform/sql/SQLiteDatabase.h (262504 => 262505)


--- trunk/Source/WebCore/platform/sql/SQLiteDatabase.h	2020-06-03 19:13:04 UTC (rev 262504)
+++ trunk/Source/WebCore/platform/sql/SQLiteDatabase.h	2020-06-03 19:13:26 UTC (rev 262505)
@@ -71,7 +71,7 @@
     bool transactionInProgress() const { return m_transactionInProgress; }
 
     // Aborts the current database operation. This is thread safe.
-    void interrupt();
+    WEBCORE_EXPORT void interrupt();
 
     int64_t lastInsertRowID();
     int lastChanges();

Modified: trunk/Source/WebKit/ChangeLog (262504 => 262505)


--- trunk/Source/WebKit/ChangeLog	2020-06-03 19:13:04 UTC (rev 262504)
+++ trunk/Source/WebKit/ChangeLog	2020-06-03 19:13:26 UTC (rev 262505)
@@ -1,3 +1,28 @@
+2020-06-03  Kate Cheney  <katherine_che...@apple.com>
+
+        Any active sqlite transactions for the ITP database should be aborted when the network process suspends.
+        https://bugs.webkit.org/show_bug.cgi?id=212608
+        <rdar://problem/60540768>
+
+        Reviewed by Chris Dumez.
+
+        Calls to WebResourceLoadStatisticsStore::suspend() should abort any
+        active SQLite transactions. Unfinished transactions will hold the lock
+        of a database file and could cause the network process to crash when
+        suspending.
+
+        * NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp:
+        (WebKit::ResourceLoadStatisticsDatabaseStore::ResourceLoadStatisticsDatabaseStore):
+        (WebKit::ResourceLoadStatisticsDatabaseStore::~ResourceLoadStatisticsDatabaseStore):
+        Store all ResourceLoadStatisticsDatabaseStore instances in a static
+        HashSet so existing transactions can be aborted when the process is
+        preparing to suspend.
+
+        (WebKit::ResourceLoadStatisticsDatabaseStore::interrupt):
+        * NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h:
+        * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:
+        (WebKit::WebResourceLoadStatisticsStore::suspend):
+
 2020-06-03  Chris Dumez  <cdu...@apple.com>
 
         WebProcessPool::notifyPreferencesChanged() is unsafely called on a background thread

Modified: trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp (262504 => 262505)


--- trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp	2020-06-03 19:13:04 UTC (rev 262504)
+++ trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp	2020-06-03 19:13:26 UTC (rev 262505)
@@ -277,7 +277,14 @@
     return createTableQueries;
 }
 
+HashSet<ResourceLoadStatisticsDatabaseStore*>& ResourceLoadStatisticsDatabaseStore::allStores()
+{
+    ASSERT(!RunLoop::isMain());
 
+    static NeverDestroyed<HashSet<ResourceLoadStatisticsDatabaseStore*>> map;
+    return map;
+}
+
 ResourceLoadStatisticsDatabaseStore::ResourceLoadStatisticsDatabaseStore(WebResourceLoadStatisticsStore& store, WorkQueue& workQueue, ShouldIncludeLocalhost shouldIncludeLocalhost, const String& storageDirectoryPath, PAL::SessionID sessionID)
     : ResourceLoadStatisticsStore(store, workQueue, shouldIncludeLocalhost)
     , m_storageDirectoryPath(storageDirectoryPath + "/observations.db")
@@ -300,11 +307,13 @@
     });
 
     includeTodayAsOperatingDateIfNecessary();
+    allStores().add(this);
 }
 
 ResourceLoadStatisticsDatabaseStore::~ResourceLoadStatisticsDatabaseStore()
 {
     close();
+    allStores().remove(this);
 }
 
 void ResourceLoadStatisticsDatabaseStore::close()
@@ -523,6 +532,12 @@
     return SQLiteStatementAutoResetScope { statement.get() };
 }
 
+void ResourceLoadStatisticsDatabaseStore::interrupt()
+{
+    if (m_database.isOpen())
+        m_database.interrupt();
+}
+
 bool ResourceLoadStatisticsDatabaseStore::isEmpty() const
 {
     ASSERT(!RunLoop::isMain());

Modified: trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h (262504 => 262505)


--- trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h	2020-06-03 19:13:04 UTC (rev 262504)
+++ trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h	2020-06-03 19:13:26 UTC (rev 262505)
@@ -81,6 +81,8 @@
 public:
     ResourceLoadStatisticsDatabaseStore(WebResourceLoadStatisticsStore&, WorkQueue&, ShouldIncludeLocalhost, const String& storageDirectoryPath, PAL::SessionID);
     ~ResourceLoadStatisticsDatabaseStore();
+
+    static HashSet<ResourceLoadStatisticsDatabaseStore*>& allStores();
     void populateFromMemoryStore(const ResourceLoadStatisticsMemoryStore&);
     void mergeStatistics(Vector<ResourceLoadStatistics>&&) override;
     void clear(CompletionHandler<void()>&&) override;
@@ -144,6 +146,7 @@
     bool domainIDExistsInDatabase(int);
     Optional<Vector<String>> checkForMissingTablesInSchema();
     void insertExpiredStatisticForTesting(const RegistrableDomain&, bool hasUserInteraction, bool isScheduledForAllButCookieDataRemoval, bool isPrevalent) override;
+    void interrupt();
 
 private:
     void includeTodayAsOperatingDateIfNecessary() override;

Modified: trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp (262504 => 262505)


--- trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp	2020-06-03 19:13:04 UTC (rev 262504)
+++ trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp	2020-06-03 19:13:26 UTC (rev 262505)
@@ -1425,6 +1425,9 @@
 
     sharedStatisticsQueue()->dispatch([completionHandler = completionHandlerCaller.release()] () mutable {
 
+        for (auto& databaseStore : ResourceLoadStatisticsDatabaseStore::allStores())
+            databaseStore->interrupt();
+        
         Locker<Lock> stateLocker(suspendedStateLock);
         ASSERT(suspendedState != State::Suspended);
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to