From ba5642c8cdbebc2d16d45b2d21eea7db15e927c9 Mon Sep 17 00:00:00 2001 From: Jan Varga Date: Fri, 4 May 2018 06:32:11 +0200 Subject: [PATCH] Bug 1411908 - Part 1: Wait for all live database objects to finish when shutting down; r=asuth --- dom/indexedDB/ActorsParent.cpp | 54 ++++++++----------- .../test/unit/test_storageOption_pref.js | 6 ++- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/dom/indexedDB/ActorsParent.cpp b/dom/indexedDB/ActorsParent.cpp index eb277e738757..1f97b8a286b5 100644 --- a/dom/indexedDB/ActorsParent.cpp +++ b/dom/indexedDB/ActorsParent.cpp @@ -6349,7 +6349,6 @@ private: bool mInvalidated; bool mActorWasAlive; bool mActorDestroyed; - bool mMetadataCleanedUp; #ifdef DEBUG bool mAllBlobsUnmapped; #endif @@ -13868,7 +13867,6 @@ Database::Database(Factory* aFactory, , mInvalidated(false) , mActorWasAlive(false) , mActorDestroyed(false) - , mMetadataCleanedUp(false) #ifdef DEBUG , mAllBlobsUnmapped(false) #endif @@ -13981,8 +13979,6 @@ Database::Invalidate() } MOZ_ALWAYS_TRUE(CloseInternal()); - - CleanupMetadata(); } nsresult @@ -14248,22 +14244,18 @@ Database::CleanupMetadata() { AssertIsOnBackgroundThread(); - if (!mMetadataCleanedUp) { - mMetadataCleanedUp = true; + DatabaseActorInfo* info; + MOZ_ALWAYS_TRUE(gLiveDatabaseHashtable->Get(Id(), &info)); + MOZ_ALWAYS_TRUE(info->mLiveDatabases.RemoveElement(this)); - DatabaseActorInfo* info; - MOZ_ALWAYS_TRUE(gLiveDatabaseHashtable->Get(Id(), &info)); - MOZ_ALWAYS_TRUE(info->mLiveDatabases.RemoveElement(this)); - - if (info->mLiveDatabases.IsEmpty()) { - MOZ_ASSERT(!info->mWaitingFactoryOp || - !info->mWaitingFactoryOp->HasBlockedDatabases()); - gLiveDatabaseHashtable->Remove(Id()); - } - - // Match the IncreaseBusyCount in OpenDatabaseOp::EnsureDatabaseActor(). - DecreaseBusyCount(); + if (info->mLiveDatabases.IsEmpty()) { + MOZ_ASSERT(!info->mWaitingFactoryOp || + !info->mWaitingFactoryOp->HasBlockedDatabases()); + gLiveDatabaseHashtable->Remove(Id()); } + + // Match the IncreaseBusyCount in OpenDatabaseOp::EnsureDatabaseActor(). + DecreaseBusyCount(); } bool @@ -17888,22 +17880,15 @@ QuotaClient::ShutdownWorkThreads() mShutdownRequested = true; - // Shutdown maintenance thread pool (this spins the event loop until all - // threads are gone). This should release any maintenance related quota - // objects. - if (mMaintenanceThreadPool) { - mMaintenanceThreadPool->Shutdown(); - mMaintenanceThreadPool = nullptr; - } + AbortOperations(VoidCString()); - // Let any runnables dispatched from dying maintenance threads to be - // processed. This should release any maintenance related directory locks. - if (mCurrentMaintenance) { - MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { - return !mCurrentMaintenance; - })); - } + // This should release any IDB related quota objects or directory locks. + MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { + return (!gLiveDatabaseHashtable || !gLiveDatabaseHashtable->Count()) && + !mCurrentMaintenance; + })); + // And finally, shutdown all threads. RefPtr connectionPool = gConnectionPool.get(); if (connectionPool) { connectionPool->Shutdown(); @@ -17918,6 +17903,11 @@ QuotaClient::ShutdownWorkThreads() gFileHandleThreadPool = nullptr; } + + if (mMaintenanceThreadPool) { + mMaintenanceThreadPool->Shutdown(); + mMaintenanceThreadPool = nullptr; + } } void diff --git a/dom/indexedDB/test/unit/test_storageOption_pref.js b/dom/indexedDB/test/unit/test_storageOption_pref.js index 894f3b56b95b..d6bb22f5f913 100644 --- a/dom/indexedDB/test/unit/test_storageOption_pref.js +++ b/dom/indexedDB/test/unit/test_storageOption_pref.js @@ -84,10 +84,14 @@ function* testSteps() request.onsuccess = grabEventAndContinueHandler; event = yield undefined; + is(event.type, "upgradeneeded", "Got correct event type"); + db = event.target.result; db.onerror = errorHandler; - is(event.type, "upgradeneeded", "Got correct event type"); + event = yield undefined; + + is(event.type, "success", "Got correct event type"); is(db.name, name, "Correct name"); is(db.version, version, "Correct version");