Layout Test imported/w3c/web-platform-tests/IndexedDB/fire-error-event-exception...
authorsihui_liu@apple.com <sihui_liu@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Oct 2019 18:26:19 +0000 (18:26 +0000)
committersihui_liu@apple.com <sihui_liu@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Oct 2019 18:26:19 +0000 (18:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=201481
<rdar://problem/55046055>

Reviewed by Alex Christensen.

We should not schedule timer if we know the timer function will be no-op.

* Modules/indexeddb/IDBTransaction.cpp:
(WebCore::IDBTransaction::removeRequest):
(WebCore::IDBTransaction::scheduleOperation):
(WebCore::IDBTransaction::trySchedulePendingOperationTimer):
(WebCore::IDBTransaction::pendingOperationTimerFired):
(WebCore::IDBTransaction::didStart):
(WebCore::IDBTransaction::operationCompletedOnClient):
(WebCore::IDBTransaction::deactivate):
(WebCore::IDBTransaction::schedulePendingOperationTimer): Deleted.
* Modules/indexeddb/IDBTransaction.h:

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/IDBTransaction.cpp
Source/WebCore/Modules/indexeddb/IDBTransaction.h

index f423f85..ffa9595 100644 (file)
@@ -1,3 +1,24 @@
+2019-10-04  Sihui Liu  <sihui_liu@apple.com>
+
+        Layout Test imported/w3c/web-platform-tests/IndexedDB/fire-error-event-exception.html is a Flaky Failure
+        https://bugs.webkit.org/show_bug.cgi?id=201481
+        <rdar://problem/55046055>
+
+        Reviewed by Alex Christensen.
+
+        We should not schedule timer if we know the timer function will be no-op.
+
+        * Modules/indexeddb/IDBTransaction.cpp:
+        (WebCore::IDBTransaction::removeRequest):
+        (WebCore::IDBTransaction::scheduleOperation):
+        (WebCore::IDBTransaction::trySchedulePendingOperationTimer):
+        (WebCore::IDBTransaction::pendingOperationTimerFired):
+        (WebCore::IDBTransaction::didStart):
+        (WebCore::IDBTransaction::operationCompletedOnClient):
+        (WebCore::IDBTransaction::deactivate):
+        (WebCore::IDBTransaction::schedulePendingOperationTimer): Deleted.
+        * Modules/indexeddb/IDBTransaction.h:
+
 2019-10-04  Chris Dumez  <cdumez@apple.com>
 
         Unreviewed follow-up fix for r250693 to address assertion hits in debug.
index 7524e0d..f08c2ea 100644 (file)
@@ -383,6 +383,8 @@ void IDBTransaction::removeRequest(IDBRequest& request)
 {
     ASSERT(&m_database->originThread() == &Thread::current());
     m_openRequests.remove(&request);
+
+    trySchedulePendingOperationTimer();
 }
 
 void IDBTransaction::scheduleOperation(Ref<IDBClient::TransactionOperation>&& operation)
@@ -394,13 +396,24 @@ void IDBTransaction::scheduleOperation(Ref<IDBClient::TransactionOperation>&& op
     m_pendingTransactionOperationQueue.append(operation.copyRef());
     m_transactionOperationMap.set(identifier, WTFMove(operation));
 
-    schedulePendingOperationTimer();
+    trySchedulePendingOperationTimer();
 }
 
-void IDBTransaction::schedulePendingOperationTimer()
+void IDBTransaction::trySchedulePendingOperationTimer()
 {
     ASSERT(&m_database->originThread() == &Thread::current());
 
+    if (!m_startedOnServer)
+        return;
+
+    // If the last in-progress operation we've sent to the server is not an IDBRequest operation,
+    // then we have to wait until it completes before sending any more.
+    if (!m_transactionOperationsInProgressQueue.isEmpty() && !m_transactionOperationsInProgressQueue.last()->nextRequestCanGoToServer())
+        return;
+
+    if (m_pendingTransactionOperationQueue.isEmpty() && (!m_transactionOperationMap.isEmpty() || !m_openRequests.isEmpty() || isFinishedOrFinishing()))
+        return;
+
     if (!m_pendingOperationTimer.isActive())
         m_pendingOperationTimer.startOneShot(0_s);
 }
@@ -410,14 +423,6 @@ void IDBTransaction::pendingOperationTimerFired()
     LOG(IndexedDB, "IDBTransaction::pendingOperationTimerFired (%p)", this);
     ASSERT(&m_database->originThread() == &Thread::current());
 
-    if (!m_startedOnServer)
-        return;
-
-    // If the last in-progress operation we've sent to the server is not an IDBRequest operation,
-    // then we have to wait until it completes before sending any more.
-    if (!m_transactionOperationsInProgressQueue.isEmpty() && !m_transactionOperationsInProgressQueue.last()->nextRequestCanGoToServer())
-        return;
-
     // We want to batch operations together without spinning the runloop for performance,
     // but don't want to affect responsiveness of the main thread.
     // This number is a good compromise in ad-hoc testing.
@@ -557,7 +562,7 @@ void IDBTransaction::didStart(const IDBError& error)
         return;
     }
 
-    schedulePendingOperationTimer();
+    trySchedulePendingOperationTimer();
 }
 
 void IDBTransaction::notifyDidAbort(const IDBError& error)
@@ -1410,7 +1415,7 @@ void IDBTransaction::operationCompletedOnClient(IDBClient::TransactionOperation&
     m_transactionOperationMap.remove(operation.identifier());
     m_transactionOperationsInProgressQueue.removeFirst();
 
-    schedulePendingOperationTimer();
+    trySchedulePendingOperationTimer();
 }
 
 void IDBTransaction::establishOnServer()
@@ -1438,7 +1443,7 @@ void IDBTransaction::deactivate()
     if (m_state == IndexedDB::TransactionState::Active)
         m_state = IndexedDB::TransactionState::Inactive;
 
-    schedulePendingOperationTimer();
+    trySchedulePendingOperationTimer();
 }
 
 void IDBTransaction::connectionClosedFromServer(const IDBError& error)
index c9234ed..3e68407 100644 (file)
@@ -229,7 +229,7 @@ private:
     void completeNoncursorRequest(IDBRequest&, const IDBResultData&);
     void completeCursorRequest(IDBRequest&, const IDBResultData&);
 
-    void schedulePendingOperationTimer();
+    void trySchedulePendingOperationTimer();
     void scheduleCompletedOperationTimer();
 
     Ref<IDBDatabase> m_database;