Title: [242029] branches/safari-607-branch/Source/WebCore
Revision
242029
Author
[email protected]
Date
2019-02-24 20:47:31 -0800 (Sun, 24 Feb 2019)

Log Message

Cherry-pick r241967. rdar://problem/48350358

    Crash under IDBServer::IDBConnectionToClient::identifier() const
    https://bugs.webkit.org/show_bug.cgi?id=194843
    <rdar://problem/48203102>

    Reviewed by Geoffrey Garen.

    UniqueIDBDatabase should ignore requests from connections that are already closed.

    Tests are hard to create without some tricks on UniqueIDBDatabase so this fix is verified manually.
    One test is created by adding delay to UniqueIDBDatabase::openBackingStore on the background thread to make sure
    disconnection of web process happens before UniqueIDBDatabase::didOpenBackingStore, because didOpenBackingStore
    may start a version change transaction and ask for identifier from the connection that is already gone.

    * Modules/indexeddb/server/IDBConnectionToClient.cpp:
    (WebCore::IDBServer::IDBConnectionToClient::connectionToClientClosed):
    * Modules/indexeddb/server/IDBConnectionToClient.h:
    (WebCore::IDBServer::IDBConnectionToClient::isClosed):
    * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
    (WebCore::IDBServer::UniqueIDBDatabase::clearStalePendingOpenDBRequests):
    (WebCore::IDBServer::UniqueIDBDatabase::handleDatabaseOperations):
    (WebCore::IDBServer::UniqueIDBDatabase::operationAndTransactionTimerFired):
    * Modules/indexeddb/server/UniqueIDBDatabase.h:

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

Modified Paths

Diff

Modified: branches/safari-607-branch/Source/WebCore/ChangeLog (242028 => 242029)


--- branches/safari-607-branch/Source/WebCore/ChangeLog	2019-02-25 04:47:27 UTC (rev 242028)
+++ branches/safari-607-branch/Source/WebCore/ChangeLog	2019-02-25 04:47:31 UTC (rev 242029)
@@ -1,5 +1,60 @@
 2019-02-24  Babak Shafiei  <[email protected]>
 
+        Cherry-pick r241967. rdar://problem/48350358
+
+    Crash under IDBServer::IDBConnectionToClient::identifier() const
+    https://bugs.webkit.org/show_bug.cgi?id=194843
+    <rdar://problem/48203102>
+    
+    Reviewed by Geoffrey Garen.
+    
+    UniqueIDBDatabase should ignore requests from connections that are already closed.
+    
+    Tests are hard to create without some tricks on UniqueIDBDatabase so this fix is verified manually.
+    One test is created by adding delay to UniqueIDBDatabase::openBackingStore on the background thread to make sure
+    disconnection of web process happens before UniqueIDBDatabase::didOpenBackingStore, because didOpenBackingStore
+    may start a version change transaction and ask for identifier from the connection that is already gone.
+    
+    * Modules/indexeddb/server/IDBConnectionToClient.cpp:
+    (WebCore::IDBServer::IDBConnectionToClient::connectionToClientClosed):
+    * Modules/indexeddb/server/IDBConnectionToClient.h:
+    (WebCore::IDBServer::IDBConnectionToClient::isClosed):
+    * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
+    (WebCore::IDBServer::UniqueIDBDatabase::clearStalePendingOpenDBRequests):
+    (WebCore::IDBServer::UniqueIDBDatabase::handleDatabaseOperations):
+    (WebCore::IDBServer::UniqueIDBDatabase::operationAndTransactionTimerFired):
+    * Modules/indexeddb/server/UniqueIDBDatabase.h:
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@241967 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-02-22  Sihui Liu  <[email protected]>
+
+            Crash under IDBServer::IDBConnectionToClient::identifier() const
+            https://bugs.webkit.org/show_bug.cgi?id=194843
+            <rdar://problem/48203102>
+
+            Reviewed by Geoffrey Garen.
+
+            UniqueIDBDatabase should ignore requests from connections that are already closed.
+
+            Tests are hard to create without some tricks on UniqueIDBDatabase so this fix is verified manually.
+            One test is created by adding delay to UniqueIDBDatabase::openBackingStore on the background thread to make sure
+            disconnection of web process happens before UniqueIDBDatabase::didOpenBackingStore, because didOpenBackingStore
+            may start a version change transaction and ask for identifier from the connection that is already gone.
+
+            * Modules/indexeddb/server/IDBConnectionToClient.cpp:
+            (WebCore::IDBServer::IDBConnectionToClient::connectionToClientClosed):
+            * Modules/indexeddb/server/IDBConnectionToClient.h:
+            (WebCore::IDBServer::IDBConnectionToClient::isClosed):
+            * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
+            (WebCore::IDBServer::UniqueIDBDatabase::clearStalePendingOpenDBRequests):
+            (WebCore::IDBServer::UniqueIDBDatabase::handleDatabaseOperations):
+            (WebCore::IDBServer::UniqueIDBDatabase::operationAndTransactionTimerFired):
+            * Modules/indexeddb/server/UniqueIDBDatabase.h:
+
+2019-02-24  Babak Shafiei  <[email protected]>
+
         Cherry-pick r241915. rdar://problem/48298733
 
     Layout Test fast/text/international/khmer-selection.html is crashing

Modified: branches/safari-607-branch/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClient.cpp (242028 => 242029)


--- branches/safari-607-branch/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClient.cpp	2019-02-25 04:47:27 UTC (rev 242028)
+++ branches/safari-607-branch/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClient.cpp	2019-02-25 04:47:31 UTC (rev 242029)
@@ -207,6 +207,7 @@
             connection->connectionClosedFromClient();
     }
 
+    m_isClosed = true;
     m_databaseConnections.clear();
 }
 

Modified: branches/safari-607-branch/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClient.h (242028 => 242029)


--- branches/safari-607-branch/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClient.h	2019-02-25 04:47:27 UTC (rev 242028)
+++ branches/safari-607-branch/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClient.h	2019-02-25 04:47:31 UTC (rev 242029)
@@ -79,12 +79,13 @@
     void registerDatabaseConnection(UniqueIDBDatabaseConnection&);
     void unregisterDatabaseConnection(UniqueIDBDatabaseConnection&);
     void connectionToClientClosed();
-
+    bool isClosed() { return m_isClosed; }
 private:
     IDBConnectionToClient(IDBConnectionToClientDelegate&);
     
     WeakPtr<IDBConnectionToClientDelegate> m_delegate;
     HashSet<UniqueIDBDatabaseConnection*> m_databaseConnections;
+    bool m_isClosed { false };
 };
 
 } // namespace IDBServer

Modified: branches/safari-607-branch/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp (242028 => 242029)


--- branches/safari-607-branch/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp	2019-02-25 04:47:27 UTC (rev 242028)
+++ branches/safari-607-branch/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp	2019-02-25 04:47:31 UTC (rev 242029)
@@ -337,6 +337,12 @@
     invokeOperationAndTransactionTimer();
 }
 
+void UniqueIDBDatabase::clearStalePendingOpenDBRequests()
+{
+    while (!m_pendingOpenDBRequests.isEmpty() && m_pendingOpenDBRequests.first()->connection().isClosed())
+        m_pendingOpenDBRequests.removeFirst();
+}
+
 void UniqueIDBDatabase::handleDatabaseOperations()
 {
     ASSERT(isMainThread());
@@ -346,7 +352,9 @@
     if (m_deleteBackingStoreInProgress)
         return;
 
-    if (m_versionChangeDatabaseConnection || m_versionChangeTransaction || m_currentOpenDBRequest) {
+    clearStalePendingOpenDBRequests();
+
+    if (m_versionChangeDatabaseConnection || m_versionChangeTransaction || (m_currentOpenDBRequest && !m_currentOpenDBRequest->connection().isClosed())) {
         // We can't start any new open-database operations right now, but we might be able to start handling a delete operation.
         if (!m_currentOpenDBRequest && !m_pendingOpenDBRequests.isEmpty() && m_pendingOpenDBRequests.first()->isDeleteRequest())
             m_currentOpenDBRequest = m_pendingOpenDBRequests.takeFirst();
@@ -358,8 +366,10 @@
         return;
     }
 
-    if (m_pendingOpenDBRequests.isEmpty())
+    if (m_pendingOpenDBRequests.isEmpty()) {
+        m_currentOpenDBRequest = nullptr;
         return;
+    }
 
     m_currentOpenDBRequest = m_pendingOpenDBRequests.takeFirst();
     LOG(IndexedDB, "UniqueIDBDatabase::handleDatabaseOperations - Popped an operation, now there are %u pending", m_pendingOpenDBRequests.size());
@@ -1558,10 +1568,9 @@
 
     // The current operation might require multiple attempts to handle, so try to
     // make further progress on it now.
-    if (m_currentOpenDBRequest)
+    if (m_currentOpenDBRequest && !m_currentOpenDBRequest->connection().isClosed())
         handleCurrentOperation();
-
-    if (!m_currentOpenDBRequest)
+    else
         handleDatabaseOperations();
 
     bool hadDeferredTransactions = false;

Modified: branches/safari-607-branch/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h (242028 => 242029)


--- branches/safari-607-branch/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h	2019-02-25 04:47:27 UTC (rev 242028)
+++ branches/safari-607-branch/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h	2019-02-25 04:47:31 UTC (rev 242029)
@@ -213,6 +213,8 @@
     RefPtr<UniqueIDBDatabaseTransaction> takeNextRunnableTransaction(bool& hadDeferredTransactions);
 
     bool prepareToFinishTransaction(UniqueIDBDatabaseTransaction&);
+    
+    void clearStalePendingOpenDBRequests();
 
     void postDatabaseTask(CrossThreadTask&&);
     void postDatabaseTaskReply(CrossThreadTask&&);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to