Title: [279512] trunk/Source/WebKit
Revision
279512
Author
cdu...@apple.com
Date
2021-07-02 13:22:56 -0700 (Fri, 02 Jul 2021)

Log Message

Regression(r278786) LocalStorageDatabase's transaction may be remain active when process gets suspended
https://bugs.webkit.org/show_bug.cgi?id=227632

Reviewed by Geoffrey Garen.

After r278786, LocalStorageDatabase has a SQL transaction that gets committed with a 500ms delay on the
storage thread. When the network process would receive the PrepareToSuspend IPC, it would suspend / hang
the storage thread, which would prevent the SQL transaction from getting committed and we would suspend
with a locked file and get killed. We now make sure to flush local storage to disk (i.e. commit that
transaction) before we suspend / hang the storage thread.

* NetworkProcess/WebStorage/StorageManagerSet.cpp:
(WebKit::StorageManagerSet::waitUntilSyncingLocalStorageFinished):
(WebKit::StorageManagerSet::flushLocalStorage):
(WebKit::StorageManagerSet::suspend):
* NetworkProcess/WebStorage/StorageManagerSet.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (279511 => 279512)


--- trunk/Source/WebKit/ChangeLog	2021-07-02 20:22:50 UTC (rev 279511)
+++ trunk/Source/WebKit/ChangeLog	2021-07-02 20:22:56 UTC (rev 279512)
@@ -1,3 +1,22 @@
+2021-07-02  Chris Dumez  <cdu...@apple.com>
+
+        Regression(r278786) LocalStorageDatabase's transaction may be remain active when process gets suspended
+        https://bugs.webkit.org/show_bug.cgi?id=227632
+
+        Reviewed by Geoffrey Garen.
+
+        After r278786, LocalStorageDatabase has a SQL transaction that gets committed with a 500ms delay on the
+        storage thread. When the network process would receive the PrepareToSuspend IPC, it would suspend / hang
+        the storage thread, which would prevent the SQL transaction from getting committed and we would suspend
+        with a locked file and get killed. We now make sure to flush local storage to disk (i.e. commit that
+        transaction) before we suspend / hang the storage thread.
+
+        * NetworkProcess/WebStorage/StorageManagerSet.cpp:
+        (WebKit::StorageManagerSet::waitUntilSyncingLocalStorageFinished):
+        (WebKit::StorageManagerSet::flushLocalStorage):
+        (WebKit::StorageManagerSet::suspend):
+        * NetworkProcess/WebStorage/StorageManagerSet.h:
+
 2021-07-02  Brady Eidson  <beid...@apple.com>
 
         WebPageProxy::setAppHighlightsVisibility might send message from a background thread, ASSERTing

Modified: trunk/Source/WebKit/NetworkProcess/WebStorage/StorageManagerSet.cpp (279511 => 279512)


--- trunk/Source/WebKit/NetworkProcess/WebStorage/StorageManagerSet.cpp	2021-07-02 20:22:50 UTC (rev 279511)
+++ trunk/Source/WebKit/NetworkProcess/WebStorage/StorageManagerSet.cpp	2021-07-02 20:22:56 UTC (rev 279512)
@@ -157,16 +157,22 @@
 
     BinarySemaphore semaphore;
     m_queue->dispatch([this, &semaphore] {
-        for (const auto& storageArea : m_storageAreas.values()) {
-            ASSERT(storageArea);
-            if (storageArea)
-                storageArea->syncToDatabase();
-        }
+        flushLocalStorage();
         semaphore.signal();
     });
     semaphore.wait();
 }
 
+void StorageManagerSet::flushLocalStorage()
+{
+    ASSERT(!RunLoop::isMain());
+    for (const auto& storageArea : m_storageAreas.values()) {
+        ASSERT(storageArea);
+        if (storageArea)
+            storageArea->syncToDatabase();
+    }
+}
+
 void StorageManagerSet::suspend(CompletionHandler<void()>&& completionHandler)
 {
     ASSERT(RunLoop::isMain());
@@ -186,6 +192,10 @@
             return;
         }
 
+        // Make sure we flush local storage to disk before we suspend the thread as we want to make sure any pending
+        // SQL transaction has been committed.
+        flushLocalStorage();
+
         m_state = State::Suspended;
         RunLoop::main().dispatch(WTFMove(completionHandler));
 

Modified: trunk/Source/WebKit/NetworkProcess/WebStorage/StorageManagerSet.h (279511 => 279512)


--- trunk/Source/WebKit/NetworkProcess/WebStorage/StorageManagerSet.h	2021-07-02 20:22:50 UTC (rev 279511)
+++ trunk/Source/WebKit/NetworkProcess/WebStorage/StorageManagerSet.h	2021-07-02 20:22:56 UTC (rev 279512)
@@ -80,6 +80,8 @@
 private:
     StorageManagerSet();
 
+    void flushLocalStorage();
+
     // Message Handlers
     void connectToLocalStorageArea(IPC::Connection&, PAL::SessionID , StorageNamespaceIdentifier, SecurityOriginData&&, ConnectToStorageAreaCallback&&);
     void connectToTransientLocalStorageArea(IPC::Connection&, PAL::SessionID , StorageNamespaceIdentifier, SecurityOriginData&&, SecurityOriginData&&, ConnectToStorageAreaCallback&&);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to