ASSERTION FAILED: !m_backingStore in WebCore::IDBServer::UniqueIDBDatabase::didDeleteBackingStore(uint64_t)
https://bugs.webkit.org/show_bug.cgi?id=197741
<rdar://problem/50625006>

Reviewed by Youenn Fablet.

If an open request is made before a delete request, open task should be performed before delete task on the
database thread. After r242911, open request needs to wait decision of StorageQuotaManager before posting task
to database thread, while delete request needs not. This makes deletion happen before open.

We need to make sure tasks are in correct order by not starting next open or delete request when database is in
the middle of open or deletion.

* Modules/indexeddb/server/UniqueIDBDatabase.cpp:
(WebCore::IDBServer::UniqueIDBDatabase::performCurrentOpenOperation):
(WebCore::IDBServer::UniqueIDBDatabase::handleDatabaseOperations):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@245488 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index c27503d..fdc28c1 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,22 @@
+2019-05-17  Sihui Liu  <sihui_liu@apple.com>
+
+        ASSERTION FAILED: !m_backingStore in WebCore::IDBServer::UniqueIDBDatabase::didDeleteBackingStore(uint64_t)
+        https://bugs.webkit.org/show_bug.cgi?id=197741
+        <rdar://problem/50625006>
+
+        Reviewed by Youenn Fablet.
+
+        If an open request is made before a delete request, open task should be performed before delete task on the
+        database thread. After r242911, open request needs to wait decision of StorageQuotaManager before posting task
+        to database thread, while delete request needs not. This makes deletion happen before open.
+
+        We need to make sure tasks are in correct order by not starting next open or delete request when database is in 
+        the middle of open or deletion.
+
+        * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
+        (WebCore::IDBServer::UniqueIDBDatabase::performCurrentOpenOperation):
+        (WebCore::IDBServer::UniqueIDBDatabase::handleDatabaseOperations):
+
 2019-05-17  Antoine Quint  <graouts@apple.com>
 
         Add a website policy to disable the legacy -webkit-overflow-scrolling:touch behavior
diff --git a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp b/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp
index 4b54d9c..b94b82c 100644
--- a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp
+++ b/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp
@@ -228,6 +228,7 @@
                     auto result = IDBResultData::error(m_currentOpenDBRequest->requestData().requestIdentifier(), IDBError { QuotaExceededError, quotaErrorMessageName("openDatabase") });
                     m_currentOpenDBRequest->connection().didOpenDatabase(result);
                     m_currentOpenDBRequest = nullptr;
+                    m_isOpeningBackingStore = false;
                     break;
                 }
                 case StorageQuotaManager::Decision::Grant:
@@ -460,7 +461,7 @@
     LOG(IndexedDB, "(main) UniqueIDBDatabase::handleDatabaseOperations - There are %u pending", m_pendingOpenDBRequests.size());
     ASSERT(!m_hardClosedForUserDelete);
 
-    if (m_deleteBackingStoreInProgress)
+    if (m_deleteBackingStoreInProgress || m_isOpeningBackingStore)
         return;
 
     clearStalePendingOpenDBRequests();